plugin-git-manager 1.2.23 → 1.2.24
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/externalVersion.js +8 -8
- package/dist/locale/en-US.json +4 -3
- package/dist/locale/vi-VN.json +4 -3
- package/dist/locale/zh-CN.json +4 -3
- package/dist/server/actions/git-actions.js +21 -8
- package/dist/server/actions/gitlab-api.js +5 -8
- package/dist/server/actions/poller.js +2 -1
- package/dist/server/actions/review.js +50 -13
- package/dist/server/actions/role-permissions.js +109 -16
- package/dist/server/actions/subtree.js +4 -8
- package/dist/server/migrations/20260730000000-migrate-legacy-repository-permissions.js +23 -7
- package/dist/server/plugin.js +42 -19
- package/dist/server/repository-access.js +505 -27
- package/dist/server/services/registry-content-service.js +137 -22
- package/dist/server/utils/get-repo-account.js +5 -2
- package/dist/server/utils/gitlab-url.js +2 -0
- package/dist/server/utils/redact.js +51 -5
- package/dist/server/utils/url-security.js +109 -0
- package/package.json +1 -1
- package/src/locale/en-US.json +4 -3
- package/src/locale/vi-VN.json +4 -3
- package/src/locale/zh-CN.json +4 -3
- package/src/server/__tests__/git-actions.test.ts +24 -0
- package/src/server/__tests__/plugin-url-security.test.ts +17 -0
- package/src/server/__tests__/poller.test.ts +37 -0
- package/src/server/__tests__/repository-access.test.ts +695 -1
- package/src/server/__tests__/review.test.ts +137 -0
- package/src/server/__tests__/role-permissions.test.ts +123 -2
- package/src/server/actions/git-actions.ts +33 -10
- package/src/server/actions/gitlab-api.ts +5 -8
- package/src/server/actions/poller.ts +2 -1
- package/src/server/actions/review.ts +74 -15
- package/src/server/actions/role-permissions.ts +136 -14
- package/src/server/actions/subtree.ts +4 -8
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +23 -8
- package/src/server/plugin.ts +46 -25
- package/src/server/repository-access.ts +737 -28
- package/src/server/services/__tests__/registry-content-service.test.ts +209 -13
- package/src/server/services/registry-content-service.ts +184 -30
- package/src/server/utils/__tests__/redact.test.ts +56 -0
- package/src/server/utils/__tests__/url-security.test.ts +85 -0
- package/src/server/utils/get-repo-account.ts +22 -4
- package/src/server/utils/gitlab-url.ts +3 -0
- package/src/server/utils/redact.ts +68 -5
- package/src/server/utils/url-security.ts +95 -0
|
@@ -39,6 +39,7 @@ function getRecordValue(record, key) {
|
|
|
39
39
|
class MigrateLegacyRepositoryPermissions extends import_server.Migration {
|
|
40
40
|
on = "afterLoad";
|
|
41
41
|
async up() {
|
|
42
|
+
var _a;
|
|
42
43
|
const resourceRepo = this.db.getRepository("rolesResources");
|
|
43
44
|
const actionsRepo = this.db.getRepository("rolesResourcesActions");
|
|
44
45
|
const repositoryResources = await resourceRepo.find({ filter: { name: "gitRepositories" } });
|
|
@@ -53,11 +54,22 @@ class MigrateLegacyRepositoryPermissions extends import_server.Migration {
|
|
|
53
54
|
const legacyRead = actions.filter((action) => getRecordValue(action, "name") === "read");
|
|
54
55
|
const legacyWrite = actions.filter((action) => getRecordValue(action, "name") === "write");
|
|
55
56
|
if (legacyRead.length === 0 && legacyWrite.length === 0) continue;
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
const readPermission = (0, import_role_permissions.getRepositoryPermissionScope)(legacyRead, ["read"]);
|
|
58
|
+
const writePermission = (0, import_role_permissions.getRepositoryPermissionScope)(legacyWrite, ["write"]);
|
|
59
|
+
if (!readPermission.supported || !writePermission.supported) {
|
|
60
|
+
(_a = this.app.log) == null ? void 0 : _a.warn(
|
|
61
|
+
`[git-manager] skipped repository permission migration for role ${String(
|
|
62
|
+
roleName
|
|
63
|
+
)} because its legacy scope cannot be represented safely`
|
|
64
|
+
);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const effectiveReadIds = [.../* @__PURE__ */ new Set([...readPermission.ids, ...writePermission.ids])];
|
|
68
|
+
const effectiveReadUnrestricted = readPermission.unrestricted || writePermission.unrestricted;
|
|
69
|
+
if (effectiveReadIds.length === 0 && !effectiveReadUnrestricted && !writePermission.unrestricted) continue;
|
|
70
|
+
await (0, import_role_permissions.syncScopedActions)(this.db, repositoryResource, import_role_permissions.REPOSITORY_READ_ACTIONS, effectiveReadIds, {
|
|
71
|
+
unrestricted: effectiveReadUnrestricted
|
|
72
|
+
});
|
|
61
73
|
let gitManagerResource = await resourceRepo.findOne({ filter: { roleName, name: "gitManager" } });
|
|
62
74
|
if (!gitManagerResource) {
|
|
63
75
|
gitManagerResource = await resourceRepo.create({
|
|
@@ -66,8 +78,12 @@ class MigrateLegacyRepositoryPermissions extends import_server.Migration {
|
|
|
66
78
|
} else if (!getRecordValue(gitManagerResource, "usingActionsConfig")) {
|
|
67
79
|
await gitManagerResource.update({ usingActionsConfig: true });
|
|
68
80
|
}
|
|
69
|
-
await (0, import_role_permissions.syncScopedActions)(this.db, gitManagerResource, import_role_permissions.GIT_READ_ACTIONS, effectiveReadIds
|
|
70
|
-
|
|
81
|
+
await (0, import_role_permissions.syncScopedActions)(this.db, gitManagerResource, import_role_permissions.GIT_READ_ACTIONS, effectiveReadIds, {
|
|
82
|
+
unrestricted: effectiveReadUnrestricted
|
|
83
|
+
});
|
|
84
|
+
await (0, import_role_permissions.syncScopedActions)(this.db, gitManagerResource, import_role_permissions.GIT_WRITE_ACTIONS, writePermission.ids, {
|
|
85
|
+
unrestricted: writePermission.unrestricted
|
|
86
|
+
});
|
|
71
87
|
for (const action of [...legacyRead, ...legacyWrite]) {
|
|
72
88
|
await action.destroy();
|
|
73
89
|
}
|
package/dist/server/plugin.js
CHANGED
|
@@ -38,7 +38,8 @@ var plugin_exports = {};
|
|
|
38
38
|
__export(plugin_exports, {
|
|
39
39
|
PluginGitManagerServer: () => PluginGitManagerServer,
|
|
40
40
|
default: () => plugin_default,
|
|
41
|
-
ensureAutoReviewFlowSchema: () => ensureAutoReviewFlowSchema
|
|
41
|
+
ensureAutoReviewFlowSchema: () => ensureAutoReviewFlowSchema,
|
|
42
|
+
isGitConfigurationUrlMutation: () => isGitConfigurationUrlMutation
|
|
42
43
|
});
|
|
43
44
|
module.exports = __toCommonJS(plugin_exports);
|
|
44
45
|
var import_server = require("@nocobase/server");
|
|
@@ -55,10 +56,26 @@ var import_ai_tools = require("./ai-tools");
|
|
|
55
56
|
var import_poller = require("./poller");
|
|
56
57
|
var import_registry_content_service = require("./services/registry-content-service");
|
|
57
58
|
var import_repository_access = require("./repository-access");
|
|
59
|
+
var import_redact = require("./utils/redact");
|
|
60
|
+
var import_url_security = require("./utils/url-security");
|
|
61
|
+
const GIT_CONFIGURATION_URL_FIELDS = /* @__PURE__ */ new Set(["repoUrl", "baseUrl"]);
|
|
62
|
+
function isGitConfigurationUrlMutation(resourceName, actionName) {
|
|
63
|
+
return typeof actionName === "string" && ["create", "update"].includes(actionName) && (0, import_redact.isGitManagerResourceResponse)(resourceName);
|
|
64
|
+
}
|
|
58
65
|
class PluginGitManagerServer extends import_server.Plugin {
|
|
59
66
|
registryContentService;
|
|
67
|
+
skillHubContentService;
|
|
60
68
|
async afterAdd() {
|
|
61
|
-
this.registryContentService = new import_registry_content_service.RegistryGitContentService(
|
|
69
|
+
this.registryContentService = new import_registry_content_service.RegistryGitContentService(
|
|
70
|
+
this.db,
|
|
71
|
+
void 0,
|
|
72
|
+
this.app.acl
|
|
73
|
+
);
|
|
74
|
+
this.skillHubContentService = new import_registry_content_service.SkillHubGitContentService(
|
|
75
|
+
this.db,
|
|
76
|
+
void 0,
|
|
77
|
+
this.app.acl
|
|
78
|
+
);
|
|
62
79
|
}
|
|
63
80
|
async beforeLoad() {
|
|
64
81
|
await this.app.db.import({
|
|
@@ -108,6 +125,7 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
108
125
|
}
|
|
109
126
|
});
|
|
110
127
|
this.app.resourceManager.use(import_repository_access.enforceRepositoryAccess);
|
|
128
|
+
this.app.resourceManager.use(import_repository_access.enforceRepositoryCollectionAccess);
|
|
111
129
|
this.app.use(async (ctx, next) => {
|
|
112
130
|
if (ctx.logger && ctx.logger.warn) {
|
|
113
131
|
const originalWarn = ctx.logger.warn.bind(ctx.logger);
|
|
@@ -229,7 +247,7 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
229
247
|
]
|
|
230
248
|
});
|
|
231
249
|
this.app.resourceManager.use(async (ctx, next) => {
|
|
232
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
250
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
233
251
|
const resource = (_a = ctx.action) == null ? void 0 : _a.resourceName;
|
|
234
252
|
if (resource === "gitSubtreeConfigs" && ["create", "update"].includes((_b = ctx.action) == null ? void 0 : _b.actionName) && ((_c = ctx.action.params) == null ? void 0 : _c.values)) {
|
|
235
253
|
try {
|
|
@@ -264,33 +282,37 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
264
282
|
}
|
|
265
283
|
}
|
|
266
284
|
}
|
|
267
|
-
if ((resource
|
|
268
|
-
|
|
285
|
+
if (isGitConfigurationUrlMutation(resource, (_g = ctx.action) == null ? void 0 : _g.actionName)) {
|
|
286
|
+
const actionParams = (_h = ctx.action) == null ? void 0 : _h.params;
|
|
287
|
+
const requestBody = (_i = ctx.request) == null ? void 0 : _i.body;
|
|
288
|
+
const hasCredentialBearingUrl = [
|
|
289
|
+
actionParams,
|
|
290
|
+
actionParams == null ? void 0 : actionParams.values,
|
|
291
|
+
requestBody,
|
|
292
|
+
requestBody == null ? void 0 : requestBody.values,
|
|
293
|
+
ctx.query,
|
|
294
|
+
(_j = ctx.request) == null ? void 0 : _j.query
|
|
295
|
+
].some((source) => (0, import_url_security.containsCredentialBearingUrlField)(source, GIT_CONFIGURATION_URL_FIELDS));
|
|
296
|
+
if (hasCredentialBearingUrl) {
|
|
297
|
+
ctx.throw(400, ctx.t(import_url_security.URL_USERINFO_NOT_ALLOWED, { ns: this.name }));
|
|
298
|
+
}
|
|
299
|
+
if (((_l = (_k = ctx.action.params) == null ? void 0 : _k.values) == null ? void 0 : _l.pat) === "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022") {
|
|
269
300
|
delete ctx.action.params.values.pat;
|
|
270
301
|
}
|
|
271
|
-
if (((
|
|
302
|
+
if (((_m = ctx.request.body) == null ? void 0 : _m.pat) === "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022") {
|
|
272
303
|
delete ctx.request.body.pat;
|
|
273
304
|
}
|
|
274
305
|
}
|
|
275
306
|
return next();
|
|
276
307
|
});
|
|
277
308
|
this.app.resourceManager.use(async (ctx, next) => {
|
|
278
|
-
var _a
|
|
309
|
+
var _a;
|
|
279
310
|
const resource = (_a = ctx.action) == null ? void 0 : _a.resourceName;
|
|
280
|
-
if (
|
|
311
|
+
if (!(0, import_redact.isGitManagerResourceResponse)(resource)) {
|
|
281
312
|
return next();
|
|
282
313
|
}
|
|
283
314
|
await next();
|
|
284
|
-
|
|
285
|
-
const items = Array.isArray(ctx.body) ? ctx.body : ((_b = ctx.body) == null ? void 0 : _b.data) ? Array.isArray(ctx.body.data) ? ctx.body.data : [ctx.body.data] : [ctx.body];
|
|
286
|
-
items.forEach((item) => {
|
|
287
|
-
var _a2;
|
|
288
|
-
if (item && typeof item === "object") {
|
|
289
|
-
if (item.pat) item.pat = "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022";
|
|
290
|
-
if ((_a2 = item.dataValues) == null ? void 0 : _a2.pat) item.dataValues.pat = "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022";
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
}
|
|
315
|
+
(0, import_redact.redactCredentialFields)(ctx.body);
|
|
294
316
|
});
|
|
295
317
|
}
|
|
296
318
|
async install() {
|
|
@@ -336,5 +358,6 @@ var plugin_default = PluginGitManagerServer;
|
|
|
336
358
|
// Annotate the CommonJS export names for ESM import in node:
|
|
337
359
|
0 && (module.exports = {
|
|
338
360
|
PluginGitManagerServer,
|
|
339
|
-
ensureAutoReviewFlowSchema
|
|
361
|
+
ensureAutoReviewFlowSchema,
|
|
362
|
+
isGitConfigurationUrlMutation
|
|
340
363
|
});
|