@certd/lib-server 1.38.12 → 1.39.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/basic/base-controller.d.ts +30 -1
- package/dist/basic/base-controller.js +69 -2
- package/dist/basic/base-service.d.ts +3 -2
- package/dist/basic/base-service.js +31 -6
- package/dist/basic/exception/base-exception.d.ts +1 -1
- package/dist/basic/index.d.ts +1 -0
- package/dist/basic/index.js +1 -0
- package/dist/basic/mode.d.ts +3 -0
- package/dist/basic/mode.js +10 -0
- package/dist/basic/result.d.ts +4 -4
- package/dist/basic/result.js +7 -7
- package/dist/system/settings/service/models.d.ts +1 -0
- package/dist/system/settings/service/models.js +1 -0
- package/dist/system/settings/service/sys-settings-service.d.ts +2 -0
- package/dist/system/settings/service/sys-settings-service.js +25 -9
- package/dist/user/access/entity/access.d.ts +1 -0
- package/dist/user/access/entity/access.js +6 -1
- package/dist/user/access/service/access-getter.d.ts +3 -2
- package/dist/user/access/service/access-getter.js +5 -3
- package/dist/user/access/service/access-service.d.ts +4 -3
- package/dist/user/access/service/access-service.js +13 -7
- package/dist/user/addon/entity/addon.d.ts +1 -0
- package/dist/user/addon/entity/addon.js +5 -0
- package/dist/user/addon/service/addon-service.d.ts +6 -3
- package/dist/user/addon/service/addon-service.js +23 -15
- package/package.json +7 -7
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { IMidwayContainer } from '@midwayjs/core';
|
|
1
2
|
import * as koa from '@midwayjs/koa';
|
|
2
3
|
export declare abstract class BaseController {
|
|
3
4
|
ctx: koa.Context;
|
|
5
|
+
applicationContext: IMidwayContainer;
|
|
4
6
|
/**
|
|
5
7
|
* 成功返回
|
|
6
8
|
* @param data 返回数据
|
|
@@ -17,9 +19,36 @@ export declare abstract class BaseController {
|
|
|
17
19
|
*/
|
|
18
20
|
fail(msg: string, code?: any): {
|
|
19
21
|
code: any;
|
|
20
|
-
|
|
22
|
+
message: string | number;
|
|
21
23
|
};
|
|
22
24
|
getUserId(): any;
|
|
23
25
|
getLoginUser(): any;
|
|
24
26
|
isAdmin(): boolean;
|
|
27
|
+
getProjectId(permission: string): Promise<number>;
|
|
28
|
+
getProjectUserId(permission: string): Promise<{
|
|
29
|
+
projectId: number;
|
|
30
|
+
userId: any;
|
|
31
|
+
}>;
|
|
32
|
+
getProjectUserIdRead(): Promise<{
|
|
33
|
+
projectId: number;
|
|
34
|
+
userId: any;
|
|
35
|
+
}>;
|
|
36
|
+
getProjectUserIdWrite(): Promise<{
|
|
37
|
+
projectId: number;
|
|
38
|
+
userId: any;
|
|
39
|
+
}>;
|
|
40
|
+
getProjectUserIdAdmin(): Promise<{
|
|
41
|
+
projectId: number;
|
|
42
|
+
userId: any;
|
|
43
|
+
}>;
|
|
44
|
+
checkProjectPermission(userId: number, projectId: number, permission: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param service 检查记录是否属于某用户或某项目
|
|
48
|
+
* @param id
|
|
49
|
+
*/
|
|
50
|
+
checkOwner(service: any, id: number, permission: string, allowAdmin?: boolean): Promise<{
|
|
51
|
+
projectId: number;
|
|
52
|
+
userId: any;
|
|
53
|
+
}>;
|
|
25
54
|
}
|
|
@@ -7,11 +7,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { Inject } from '@midwayjs/core';
|
|
10
|
+
import { ApplicationContext, Inject } from '@midwayjs/core';
|
|
11
11
|
import * as koa from '@midwayjs/koa';
|
|
12
12
|
import { Constants } from './constants.js';
|
|
13
|
+
import { isEnterprise } from './mode.js';
|
|
13
14
|
export class BaseController {
|
|
14
15
|
ctx;
|
|
16
|
+
applicationContext;
|
|
15
17
|
/**
|
|
16
18
|
* 成功返回
|
|
17
19
|
* @param data 返回数据
|
|
@@ -34,7 +36,7 @@ export class BaseController {
|
|
|
34
36
|
fail(msg, code) {
|
|
35
37
|
return {
|
|
36
38
|
code: code ? code : Constants.res.error.code,
|
|
37
|
-
|
|
39
|
+
message: msg ? msg : Constants.res.error.code,
|
|
38
40
|
};
|
|
39
41
|
}
|
|
40
42
|
getUserId() {
|
|
@@ -57,8 +59,73 @@ export class BaseController {
|
|
|
57
59
|
return true;
|
|
58
60
|
}
|
|
59
61
|
}
|
|
62
|
+
async getProjectId(permission) {
|
|
63
|
+
if (!isEnterprise()) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
let projectIdStr = this.ctx.headers["project-id"];
|
|
67
|
+
if (!projectIdStr) {
|
|
68
|
+
projectIdStr = this.ctx.request.query["projectId"];
|
|
69
|
+
}
|
|
70
|
+
if (!projectIdStr) {
|
|
71
|
+
//这里必须抛异常,否则可能会有权限问题
|
|
72
|
+
throw new Error("projectId 不能为空");
|
|
73
|
+
}
|
|
74
|
+
const userId = this.getUserId();
|
|
75
|
+
const projectId = parseInt(projectIdStr);
|
|
76
|
+
await this.checkProjectPermission(userId, projectId, permission);
|
|
77
|
+
return projectId;
|
|
78
|
+
}
|
|
79
|
+
async getProjectUserId(permission) {
|
|
80
|
+
let userId = this.getUserId();
|
|
81
|
+
const projectId = await this.getProjectId(permission);
|
|
82
|
+
if (projectId) {
|
|
83
|
+
userId = -1; // 企业管理模式下,用户id固定-1
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
projectId, userId
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
async getProjectUserIdRead() {
|
|
90
|
+
return await this.getProjectUserId("read");
|
|
91
|
+
}
|
|
92
|
+
async getProjectUserIdWrite() {
|
|
93
|
+
return await this.getProjectUserId("write");
|
|
94
|
+
}
|
|
95
|
+
async getProjectUserIdAdmin() {
|
|
96
|
+
return await this.getProjectUserId("admin");
|
|
97
|
+
}
|
|
98
|
+
async checkProjectPermission(userId, projectId, permission) {
|
|
99
|
+
const projectService = await this.applicationContext.getAsync("projectService");
|
|
100
|
+
await projectService.checkPermission({ userId, projectId, permission });
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
*
|
|
104
|
+
* @param service 检查记录是否属于某用户或某项目
|
|
105
|
+
* @param id
|
|
106
|
+
*/
|
|
107
|
+
async checkOwner(service, id, permission, allowAdmin = false) {
|
|
108
|
+
let { projectId, userId } = await this.getProjectUserId(permission);
|
|
109
|
+
const authService = await this.applicationContext.getAsync("authService");
|
|
110
|
+
if (projectId) {
|
|
111
|
+
await authService.checkProjectId(service, id, projectId);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
if (allowAdmin) {
|
|
115
|
+
await authService.checkUserIdButAllowAdmin(this.ctx, service, id);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
await authService.checkUserId(service, id, userId);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return { projectId, userId };
|
|
122
|
+
}
|
|
60
123
|
}
|
|
61
124
|
__decorate([
|
|
62
125
|
Inject(),
|
|
63
126
|
__metadata("design:type", Object)
|
|
64
127
|
], BaseController.prototype, "ctx", void 0);
|
|
128
|
+
__decorate([
|
|
129
|
+
ApplicationContext(),
|
|
130
|
+
__metadata("design:type", Object)
|
|
131
|
+
], BaseController.prototype, "applicationContext", void 0);
|
|
@@ -83,7 +83,8 @@ export declare abstract class BaseService<T> {
|
|
|
83
83
|
* 分页查询
|
|
84
84
|
*/
|
|
85
85
|
list(listReq: ListReq<T>): Promise<T[]>;
|
|
86
|
-
checkUserId(
|
|
87
|
-
batchDelete(ids: number[], userId: number): Promise<void>;
|
|
86
|
+
checkUserId(ids: number | number[], userId: number, userKey?: string): Promise<void>;
|
|
87
|
+
batchDelete(ids: number[], userId: number, projectId?: number): Promise<void>;
|
|
88
88
|
findOne(options: FindOneOptions<T>): Promise<T>;
|
|
89
89
|
}
|
|
90
|
+
export declare function checkUserProjectParam(userId: number, projectId: number): boolean;
|
|
@@ -181,29 +181,40 @@ export class BaseService {
|
|
|
181
181
|
const qb = this.buildListQuery(listReq);
|
|
182
182
|
return await qb.getMany();
|
|
183
183
|
}
|
|
184
|
-
async checkUserId(
|
|
185
|
-
|
|
184
|
+
async checkUserId(ids = 0, userId, userKey = 'userId') {
|
|
185
|
+
if (ids == null) {
|
|
186
|
+
throw new ValidateException('id不能为空');
|
|
187
|
+
}
|
|
188
|
+
if (userId == null) {
|
|
189
|
+
throw new ValidateException('userId不能为空');
|
|
190
|
+
}
|
|
191
|
+
if (!Array.isArray(ids)) {
|
|
192
|
+
ids = [ids];
|
|
193
|
+
}
|
|
194
|
+
const res = await this.getRepository().find({
|
|
186
195
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
187
196
|
// @ts-ignore
|
|
188
197
|
select: { [userKey]: true },
|
|
189
198
|
where: {
|
|
190
199
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
191
200
|
// @ts-ignore
|
|
192
|
-
id,
|
|
201
|
+
id: In(ids),
|
|
202
|
+
[userKey]: userId,
|
|
193
203
|
},
|
|
194
204
|
});
|
|
195
|
-
if (!res || res
|
|
205
|
+
if (!res || res.length === ids.length) {
|
|
196
206
|
return;
|
|
197
207
|
}
|
|
198
208
|
throw new PermissionException('权限不足');
|
|
199
209
|
}
|
|
200
|
-
async batchDelete(ids, userId) {
|
|
201
|
-
if (userId
|
|
210
|
+
async batchDelete(ids, userId, projectId) {
|
|
211
|
+
if (userId != null) {
|
|
202
212
|
const list = await this.getRepository().find({
|
|
203
213
|
where: {
|
|
204
214
|
// @ts-ignore
|
|
205
215
|
id: In(ids),
|
|
206
216
|
userId,
|
|
217
|
+
projectId,
|
|
207
218
|
},
|
|
208
219
|
});
|
|
209
220
|
// @ts-ignore
|
|
@@ -219,3 +230,17 @@ __decorate([
|
|
|
219
230
|
Inject(),
|
|
220
231
|
__metadata("design:type", TypeORMDataSourceManager)
|
|
221
232
|
], BaseService.prototype, "dataSourceManager", void 0);
|
|
233
|
+
export function checkUserProjectParam(userId, projectId) {
|
|
234
|
+
if (projectId != null) {
|
|
235
|
+
if (userId !== -1) {
|
|
236
|
+
throw new ValidateException('userId projectId 错误');
|
|
237
|
+
}
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
if (userId != null) {
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
throw new ValidateException('userId不能为空');
|
|
245
|
+
}
|
|
246
|
+
}
|
package/dist/basic/index.d.ts
CHANGED
package/dist/basic/index.js
CHANGED
package/dist/basic/result.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare class Result<T> {
|
|
2
2
|
code: number;
|
|
3
|
-
|
|
3
|
+
message: string;
|
|
4
4
|
data: T;
|
|
5
|
-
constructor(code: any,
|
|
6
|
-
static error(code: number,
|
|
7
|
-
static success(
|
|
5
|
+
constructor(code: any, message: any, data?: any);
|
|
6
|
+
static error(code: number, message: any, data?: any): Result<unknown>;
|
|
7
|
+
static success(message: any, data?: any): Result<unknown>;
|
|
8
8
|
}
|
package/dist/basic/result.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export class Result {
|
|
2
2
|
code;
|
|
3
|
-
|
|
3
|
+
message;
|
|
4
4
|
data;
|
|
5
|
-
constructor(code,
|
|
5
|
+
constructor(code, message, data) {
|
|
6
6
|
this.code = code;
|
|
7
|
-
this.
|
|
7
|
+
this.message = message;
|
|
8
8
|
this.data = data;
|
|
9
9
|
}
|
|
10
|
-
static error(code = 1,
|
|
11
|
-
return new Result(code,
|
|
10
|
+
static error(code = 1, message, data) {
|
|
11
|
+
return new Result(code, message, data);
|
|
12
12
|
}
|
|
13
|
-
static success(
|
|
14
|
-
return new Result(0,
|
|
13
|
+
static success(message, data) {
|
|
14
|
+
return new Result(0, message, data);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -18,6 +18,8 @@ export declare class SysSettingsService extends BaseService<SysSettingsEntity> {
|
|
|
18
18
|
savePublicSettings(bean: SysPublicSettings): Promise<void>;
|
|
19
19
|
getPrivateSettings(): Promise<SysPrivateSettings>;
|
|
20
20
|
savePrivateSettings(bean: SysPrivateSettings): Promise<void>;
|
|
21
|
+
reloadSettings(): Promise<void>;
|
|
22
|
+
reloadPublicSettings(): Promise<void>;
|
|
21
23
|
reloadPrivateSettings(): Promise<void>;
|
|
22
24
|
updateByKey(key: string, setting: any): Promise<void>;
|
|
23
25
|
backupSecret(): Promise<void>;
|
|
@@ -15,8 +15,9 @@ import { SysInstallInfo, SysPrivateSettings, SysPublicSettings, SysSecret, SysSe
|
|
|
15
15
|
import { getAllSslProviderDomains, setSslProviderReverseProxies } from '@certd/acme-client';
|
|
16
16
|
import { cache, logger, mergeUtils, setGlobalProxy } from '@certd/basic';
|
|
17
17
|
import * as dns from 'node:dns';
|
|
18
|
-
import { BaseService } from '../../../basic/index.js';
|
|
18
|
+
import { BaseService, setAdminMode } from '../../../basic/index.js';
|
|
19
19
|
import { executorQueue } from '../../basic/service/executor-queue.js';
|
|
20
|
+
import { isComm } from '@certd/plus-core';
|
|
20
21
|
const { merge } = mergeUtils;
|
|
21
22
|
/**
|
|
22
23
|
* 设置
|
|
@@ -111,7 +112,14 @@ let SysSettingsService = class SysSettingsService extends BaseService {
|
|
|
111
112
|
return await this.getSetting(SysPublicSettings);
|
|
112
113
|
}
|
|
113
114
|
async savePublicSettings(bean) {
|
|
115
|
+
if (isComm()) {
|
|
116
|
+
if (bean.adminMode === 'enterprise') {
|
|
117
|
+
throw new Error("商业版不支持使用企业管理模式");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
114
120
|
await this.saveSetting(bean);
|
|
121
|
+
//让设置生效
|
|
122
|
+
await this.reloadPublicSettings();
|
|
115
123
|
}
|
|
116
124
|
async getPrivateSettings() {
|
|
117
125
|
const res = await this.getSetting(SysPrivateSettings);
|
|
@@ -128,20 +136,28 @@ let SysSettingsService = class SysSettingsService extends BaseService {
|
|
|
128
136
|
//让设置生效
|
|
129
137
|
await this.reloadPrivateSettings();
|
|
130
138
|
}
|
|
139
|
+
async reloadSettings() {
|
|
140
|
+
await this.reloadPrivateSettings();
|
|
141
|
+
await this.reloadPublicSettings();
|
|
142
|
+
}
|
|
143
|
+
async reloadPublicSettings() {
|
|
144
|
+
const publicSetting = await this.getPublicSettings();
|
|
145
|
+
setAdminMode(publicSetting.adminMode);
|
|
146
|
+
}
|
|
131
147
|
async reloadPrivateSettings() {
|
|
132
|
-
const
|
|
148
|
+
const privateSetting = await this.getPrivateSettings();
|
|
133
149
|
const opts = {
|
|
134
|
-
httpProxy:
|
|
135
|
-
httpsProxy:
|
|
150
|
+
httpProxy: privateSetting.httpProxy,
|
|
151
|
+
httpsProxy: privateSetting.httpsProxy,
|
|
136
152
|
};
|
|
137
153
|
setGlobalProxy(opts);
|
|
138
|
-
if (
|
|
139
|
-
dns.setDefaultResultOrder(
|
|
154
|
+
if (privateSetting.dnsResultOrder) {
|
|
155
|
+
dns.setDefaultResultOrder(privateSetting.dnsResultOrder);
|
|
140
156
|
}
|
|
141
|
-
if (
|
|
142
|
-
executorQueue.setMaxRunningCount(
|
|
157
|
+
if (privateSetting.pipelineMaxRunningCount) {
|
|
158
|
+
executorQueue.setMaxRunningCount(privateSetting.pipelineMaxRunningCount);
|
|
143
159
|
}
|
|
144
|
-
setSslProviderReverseProxies(
|
|
160
|
+
setSslProviderReverseProxies(privateSetting.reverseProxies);
|
|
145
161
|
}
|
|
146
162
|
async updateByKey(key, setting) {
|
|
147
163
|
const entity = await this.getByKey(key);
|
|
@@ -13,11 +13,12 @@ import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
|
13
13
|
*/
|
|
14
14
|
let AccessEntity = class AccessEntity {
|
|
15
15
|
id;
|
|
16
|
-
userId;
|
|
16
|
+
userId; // 0为系统级别, -1为企业,大于1为用户
|
|
17
17
|
name;
|
|
18
18
|
type;
|
|
19
19
|
setting;
|
|
20
20
|
encryptSetting;
|
|
21
|
+
projectId;
|
|
21
22
|
createTime;
|
|
22
23
|
updateTime;
|
|
23
24
|
};
|
|
@@ -45,6 +46,10 @@ __decorate([
|
|
|
45
46
|
Column({ name: 'encrypt_setting', comment: '已加密设置', length: 10240, nullable: true }),
|
|
46
47
|
__metadata("design:type", String)
|
|
47
48
|
], AccessEntity.prototype, "encryptSetting", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
Column({ name: 'project_id', comment: '项目id' }),
|
|
51
|
+
__metadata("design:type", Number)
|
|
52
|
+
], AccessEntity.prototype, "projectId", void 0);
|
|
48
53
|
__decorate([
|
|
49
54
|
Column({
|
|
50
55
|
name: 'create_time',
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { IAccessService } from '@certd/pipeline';
|
|
2
2
|
export declare class AccessGetter implements IAccessService {
|
|
3
3
|
userId: number;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
projectId?: number;
|
|
5
|
+
getter: <T>(id: any, userId?: number, projectId?: number) => Promise<T>;
|
|
6
|
+
constructor(userId: number, projectId: number, getter: (id: any, userId: number, projectId?: number) => Promise<any>);
|
|
6
7
|
getById<T = any>(id: any): Promise<T>;
|
|
7
8
|
getCommonById<T = any>(id: any): Promise<T>;
|
|
8
9
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
export class AccessGetter {
|
|
2
2
|
userId;
|
|
3
|
+
projectId;
|
|
3
4
|
getter;
|
|
4
|
-
constructor(userId, getter) {
|
|
5
|
+
constructor(userId, projectId, getter) {
|
|
5
6
|
this.userId = userId;
|
|
7
|
+
this.projectId = projectId;
|
|
6
8
|
this.getter = getter;
|
|
7
9
|
}
|
|
8
10
|
async getById(id) {
|
|
9
|
-
return await this.getter(id, this.userId);
|
|
11
|
+
return await this.getter(id, this.userId, this.projectId);
|
|
10
12
|
}
|
|
11
13
|
async getCommonById(id) {
|
|
12
|
-
return await this.getter(id, 0);
|
|
14
|
+
return await this.getter(id, 0, null);
|
|
13
15
|
}
|
|
14
16
|
}
|
|
@@ -28,9 +28,10 @@ export declare class AccessService extends BaseService<AccessEntity> {
|
|
|
28
28
|
id: number;
|
|
29
29
|
name: string;
|
|
30
30
|
userId: number;
|
|
31
|
+
projectId: number;
|
|
31
32
|
}>;
|
|
32
|
-
getAccessById(id: any, checkUserId: boolean, userId?: number): Promise<any>;
|
|
33
|
-
getById(id: any, userId: number): Promise<any>;
|
|
33
|
+
getAccessById(id: any, checkUserId: boolean, userId?: number, projectId?: number): Promise<any>;
|
|
34
|
+
getById(id: any, userId: number, projectId?: number): Promise<any>;
|
|
34
35
|
decryptAccessEntity(entity: AccessEntity): any;
|
|
35
36
|
getDefineList(): {
|
|
36
37
|
key: string;
|
|
@@ -42,5 +43,5 @@ export declare class AccessService extends BaseService<AccessEntity> {
|
|
|
42
43
|
order?: number;
|
|
43
44
|
}[];
|
|
44
45
|
getDefineByType(type: string): import("@certd/pipeline").Registrable;
|
|
45
|
-
getSimpleByIds(ids: number[], userId: any): Promise<AccessEntity[]>;
|
|
46
|
+
getSimpleByIds(ids: number[], userId: any, projectId?: number): Promise<AccessEntity[]>;
|
|
46
47
|
}
|
|
@@ -125,9 +125,10 @@ let AccessService = class AccessService extends BaseService {
|
|
|
125
125
|
id: entity.id,
|
|
126
126
|
name: entity.name,
|
|
127
127
|
userId: entity.userId,
|
|
128
|
+
projectId: entity.projectId,
|
|
128
129
|
};
|
|
129
130
|
}
|
|
130
|
-
async getAccessById(id, checkUserId, userId) {
|
|
131
|
+
async getAccessById(id, checkUserId, userId, projectId) {
|
|
131
132
|
const entity = await this.info(id);
|
|
132
133
|
if (entity == null) {
|
|
133
134
|
throw new Error(`该授权配置不存在,请确认是否已被删除:id=${id}`);
|
|
@@ -140,17 +141,20 @@ let AccessService = class AccessService extends BaseService {
|
|
|
140
141
|
throw new PermissionException('您对该Access授权无访问权限');
|
|
141
142
|
}
|
|
142
143
|
}
|
|
144
|
+
if (projectId != null && projectId !== entity.projectId) {
|
|
145
|
+
throw new PermissionException('您对该Access授权无访问权限');
|
|
146
|
+
}
|
|
143
147
|
// const access = accessRegistry.get(entity.type);
|
|
144
148
|
const setting = this.decryptAccessEntity(entity);
|
|
145
149
|
const input = {
|
|
146
150
|
id: entity.id,
|
|
147
151
|
...setting,
|
|
148
152
|
};
|
|
149
|
-
const accessGetter = new AccessGetter(userId, this.getById.bind(this));
|
|
153
|
+
const accessGetter = new AccessGetter(userId, projectId, this.getById.bind(this));
|
|
150
154
|
return await newAccess(entity.type, input, accessGetter);
|
|
151
155
|
}
|
|
152
|
-
async getById(id, userId) {
|
|
153
|
-
return await this.getAccessById(id, true, userId);
|
|
156
|
+
async getById(id, userId, projectId) {
|
|
157
|
+
return await this.getAccessById(id, true, userId, projectId);
|
|
154
158
|
}
|
|
155
159
|
decryptAccessEntity(entity) {
|
|
156
160
|
let setting = {};
|
|
@@ -177,23 +181,25 @@ let AccessService = class AccessService extends BaseService {
|
|
|
177
181
|
getDefineByType(type) {
|
|
178
182
|
return accessRegistry.getDefine(type);
|
|
179
183
|
}
|
|
180
|
-
async getSimpleByIds(ids, userId) {
|
|
184
|
+
async getSimpleByIds(ids, userId, projectId) {
|
|
181
185
|
if (ids.length === 0) {
|
|
182
186
|
return [];
|
|
183
187
|
}
|
|
184
|
-
if (
|
|
188
|
+
if (userId == null) {
|
|
185
189
|
return [];
|
|
186
190
|
}
|
|
187
191
|
return await this.repository.find({
|
|
188
192
|
where: {
|
|
189
193
|
id: In(ids),
|
|
190
194
|
userId,
|
|
195
|
+
projectId,
|
|
191
196
|
},
|
|
192
197
|
select: {
|
|
193
198
|
id: true,
|
|
194
199
|
name: true,
|
|
195
200
|
type: true,
|
|
196
|
-
userId: true
|
|
201
|
+
userId: true,
|
|
202
|
+
projectId: true,
|
|
197
203
|
},
|
|
198
204
|
});
|
|
199
205
|
}
|
|
@@ -19,6 +19,7 @@ let AddonEntity = class AddonEntity {
|
|
|
19
19
|
setting;
|
|
20
20
|
isSystem;
|
|
21
21
|
isDefault;
|
|
22
|
+
projectId;
|
|
22
23
|
createTime;
|
|
23
24
|
updateTime;
|
|
24
25
|
};
|
|
@@ -54,6 +55,10 @@ __decorate([
|
|
|
54
55
|
Column({ name: 'is_default', comment: '是否默认', nullable: false, default: false }),
|
|
55
56
|
__metadata("design:type", Boolean)
|
|
56
57
|
], AddonEntity.prototype, "isDefault", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
Column({ name: 'project_id', comment: '项目id' }),
|
|
60
|
+
__metadata("design:type", Number)
|
|
61
|
+
], AddonEntity.prototype, "projectId", void 0);
|
|
57
62
|
__decorate([
|
|
58
63
|
Column({
|
|
59
64
|
name: 'create_time',
|
|
@@ -27,6 +27,7 @@ export declare class AddonService extends BaseService<AddonEntity> {
|
|
|
27
27
|
userId: number;
|
|
28
28
|
addonType: string;
|
|
29
29
|
type: string;
|
|
30
|
+
projectId: number;
|
|
30
31
|
}>;
|
|
31
32
|
getDefineList(addonType: string): {
|
|
32
33
|
key: string;
|
|
@@ -38,19 +39,21 @@ export declare class AddonService extends BaseService<AddonEntity> {
|
|
|
38
39
|
order?: number;
|
|
39
40
|
}[];
|
|
40
41
|
getDefineByType(type: string, prefix?: string): AddonDefine;
|
|
41
|
-
getSimpleByIds(ids: number[], userId: any): Promise<AddonEntity[]>;
|
|
42
|
-
getDefault(userId: number, addonType: string): Promise<any>;
|
|
42
|
+
getSimpleByIds(ids: number[], userId: any, projectId?: number): Promise<AddonEntity[]>;
|
|
43
|
+
getDefault(userId: number, addonType: string, projectId?: number): Promise<any>;
|
|
43
44
|
private buildAddonInstanceConfig;
|
|
44
|
-
setDefault(id: number, userId: number, addonType: string): Promise<void>;
|
|
45
|
+
setDefault(id: number, userId: number, addonType: string, projectId?: number): Promise<void>;
|
|
45
46
|
getOrCreateDefault(opts: {
|
|
46
47
|
addonType: string;
|
|
47
48
|
type: string;
|
|
48
49
|
inputs: any;
|
|
49
50
|
userId: any;
|
|
51
|
+
projectId?: number;
|
|
50
52
|
}): Promise<any>;
|
|
51
53
|
getOneByType(req: {
|
|
52
54
|
addonType: string;
|
|
53
55
|
type: string;
|
|
54
56
|
userId: number;
|
|
57
|
+
projectId?: number;
|
|
55
58
|
}): Promise<AddonEntity>;
|
|
56
59
|
}
|
|
@@ -70,7 +70,8 @@ let AddonService = class AddonService extends BaseService {
|
|
|
70
70
|
name: entity.name,
|
|
71
71
|
userId: entity.userId,
|
|
72
72
|
addonType: entity.addonType,
|
|
73
|
-
type: entity.type
|
|
73
|
+
type: entity.type,
|
|
74
|
+
projectId: entity.projectId
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
77
|
getDefineList(addonType) {
|
|
@@ -79,17 +80,18 @@ let AddonService = class AddonService extends BaseService {
|
|
|
79
80
|
getDefineByType(type, prefix) {
|
|
80
81
|
return addonRegistry.getDefine(type, prefix);
|
|
81
82
|
}
|
|
82
|
-
async getSimpleByIds(ids, userId) {
|
|
83
|
+
async getSimpleByIds(ids, userId, projectId) {
|
|
83
84
|
if (ids.length === 0) {
|
|
84
85
|
return [];
|
|
85
86
|
}
|
|
86
|
-
if (
|
|
87
|
+
if (userId == null) {
|
|
87
88
|
return [];
|
|
88
89
|
}
|
|
89
90
|
return await this.repository.find({
|
|
90
91
|
where: {
|
|
91
92
|
id: In(ids),
|
|
92
|
-
userId
|
|
93
|
+
userId,
|
|
94
|
+
projectId
|
|
93
95
|
},
|
|
94
96
|
select: {
|
|
95
97
|
id: true,
|
|
@@ -101,11 +103,12 @@ let AddonService = class AddonService extends BaseService {
|
|
|
101
103
|
}
|
|
102
104
|
});
|
|
103
105
|
}
|
|
104
|
-
async getDefault(userId, addonType) {
|
|
106
|
+
async getDefault(userId, addonType, projectId) {
|
|
105
107
|
const res = await this.repository.findOne({
|
|
106
108
|
where: {
|
|
107
109
|
userId,
|
|
108
|
-
addonType
|
|
110
|
+
addonType,
|
|
111
|
+
projectId
|
|
109
112
|
},
|
|
110
113
|
order: {
|
|
111
114
|
isDefault: "DESC"
|
|
@@ -124,34 +127,37 @@ let AddonService = class AddonService extends BaseService {
|
|
|
124
127
|
type: res.type,
|
|
125
128
|
name: res.name,
|
|
126
129
|
userId: res.userId,
|
|
127
|
-
setting
|
|
130
|
+
setting,
|
|
131
|
+
projectId: res.projectId
|
|
128
132
|
};
|
|
129
133
|
}
|
|
130
|
-
async setDefault(id, userId, addonType) {
|
|
134
|
+
async setDefault(id, userId, addonType, projectId) {
|
|
131
135
|
if (!id) {
|
|
132
136
|
throw new ValidateException("id不能为空");
|
|
133
137
|
}
|
|
134
|
-
if (
|
|
138
|
+
if (userId == null) {
|
|
135
139
|
throw new ValidateException("userId不能为空");
|
|
136
140
|
}
|
|
137
141
|
await this.repository.update({
|
|
138
142
|
userId,
|
|
139
|
-
addonType
|
|
143
|
+
addonType,
|
|
144
|
+
projectId
|
|
140
145
|
}, {
|
|
141
146
|
isDefault: false
|
|
142
147
|
});
|
|
143
148
|
await this.repository.update({
|
|
144
149
|
id,
|
|
145
150
|
userId,
|
|
146
|
-
addonType
|
|
151
|
+
addonType,
|
|
152
|
+
projectId
|
|
147
153
|
}, {
|
|
148
154
|
isDefault: true
|
|
149
155
|
});
|
|
150
156
|
}
|
|
151
157
|
async getOrCreateDefault(opts) {
|
|
152
|
-
const { addonType, type, inputs, userId } = opts;
|
|
158
|
+
const { addonType, type, inputs, userId, projectId } = opts;
|
|
153
159
|
const addonDefine = this.getDefineByType(type, addonType);
|
|
154
|
-
const defaultConfig = await this.getDefault(userId, addonType);
|
|
160
|
+
const defaultConfig = await this.getDefault(userId, addonType, projectId);
|
|
155
161
|
if (defaultConfig) {
|
|
156
162
|
return defaultConfig;
|
|
157
163
|
}
|
|
@@ -164,7 +170,8 @@ let AddonService = class AddonService extends BaseService {
|
|
|
164
170
|
type: type,
|
|
165
171
|
name: addonDefine.title,
|
|
166
172
|
setting: JSON.stringify(setting),
|
|
167
|
-
isDefault: true
|
|
173
|
+
isDefault: true,
|
|
174
|
+
projectId
|
|
168
175
|
});
|
|
169
176
|
return this.buildAddonInstanceConfig(res);
|
|
170
177
|
}
|
|
@@ -173,7 +180,8 @@ let AddonService = class AddonService extends BaseService {
|
|
|
173
180
|
where: {
|
|
174
181
|
addonType: req.addonType,
|
|
175
182
|
type: req.type,
|
|
176
|
-
userId: req.userId
|
|
183
|
+
userId: req.userId,
|
|
184
|
+
projectId: req.projectId
|
|
177
185
|
}
|
|
178
186
|
});
|
|
179
187
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@certd/lib-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.39.1",
|
|
4
4
|
"description": "midway with flyway, sql upgrade way ",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
],
|
|
29
29
|
"license": "AGPL",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@certd/acme-client": "^1.
|
|
32
|
-
"@certd/basic": "^1.
|
|
33
|
-
"@certd/pipeline": "^1.
|
|
34
|
-
"@certd/plugin-lib": "^1.
|
|
35
|
-
"@certd/plus-core": "^1.
|
|
31
|
+
"@certd/acme-client": "^1.39.1",
|
|
32
|
+
"@certd/basic": "^1.39.1",
|
|
33
|
+
"@certd/pipeline": "^1.39.1",
|
|
34
|
+
"@certd/plugin-lib": "^1.39.1",
|
|
35
|
+
"@certd/plus-core": "^1.39.1",
|
|
36
36
|
"@midwayjs/cache": "3.14.0",
|
|
37
37
|
"@midwayjs/core": "3.20.11",
|
|
38
38
|
"@midwayjs/i18n": "3.20.13",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"typeorm": "^0.3.11",
|
|
65
65
|
"typescript": "^5.4.2"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "590ff67fcb40ff8ba0f7b2a9592b51d9fb54a2ef"
|
|
68
68
|
}
|