plugin-git-manager 1.2.20 → 1.2.23
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/client/{434.1d19d4d6acc114f1.js → 434.b2eeaaef33aae6e0.js} +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client-v2/{434.f8836ea116648de1.js → 434.7a27051db18526c0.js} +1 -1
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +8 -8
- package/dist/locale/en-US.json +1 -0
- package/dist/locale/vi-VN.json +1 -0
- package/dist/locale/zh-CN.json +1 -0
- package/dist/server/actions/git-actions.js +7 -0
- package/dist/server/actions/role-permissions.js +124 -54
- package/dist/server/collections/gitRepositories.js +8 -0
- package/dist/server/migrations/20260730000000-migrate-legacy-repository-permissions.js +78 -0
- package/dist/server/plugin.js +16 -4
- package/dist/server/repository-access.js +92 -0
- package/dist/server/services/registry-content-service.js +296 -0
- package/package.json +1 -1
- package/src/client/components/RepositoryConfig.tsx +4 -1
- package/src/locale/en-US.json +1 -0
- package/src/locale/vi-VN.json +1 -0
- package/src/locale/zh-CN.json +1 -0
- package/src/server/__tests__/repository-access.test.ts +58 -0
- package/src/server/__tests__/role-permissions.test.ts +26 -0
- package/src/server/actions/git-actions.ts +5 -1
- package/src/server/actions/role-permissions.ts +129 -59
- package/src/server/collections/gitRepositories.ts +8 -0
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +66 -0
- package/src/server/plugin.ts +20 -4
- package/src/server/repository-access.ts +64 -0
- package/src/server/services/__tests__/registry-content-service.test.ts +149 -0
- package/src/server/services/registry-content-service.ts +315 -0
|
@@ -26,12 +26,93 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
26
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
27
|
var role_permissions_exports = {};
|
|
28
28
|
__export(role_permissions_exports, {
|
|
29
|
+
GIT_READ_ACTIONS: () => GIT_READ_ACTIONS,
|
|
30
|
+
GIT_WRITE_ACTIONS: () => GIT_WRITE_ACTIONS,
|
|
31
|
+
REPOSITORY_READ_ACTIONS: () => REPOSITORY_READ_ACTIONS,
|
|
32
|
+
getRepositoryPermissionIds: () => getRepositoryPermissionIds,
|
|
29
33
|
rolePermissions: () => rolePermissions,
|
|
34
|
+
syncScopedActions: () => syncScopedActions,
|
|
30
35
|
updateRolePermissions: () => updateRolePermissions
|
|
31
36
|
});
|
|
32
37
|
module.exports = __toCommonJS(role_permissions_exports);
|
|
33
38
|
function getRecordValue(record, key) {
|
|
34
|
-
|
|
39
|
+
if (!record || typeof record !== "object") return void 0;
|
|
40
|
+
const model = record;
|
|
41
|
+
return typeof model.get === "function" ? model.get(key) : model[key];
|
|
42
|
+
}
|
|
43
|
+
const REPOSITORY_READ_ACTIONS = ["list", "get"];
|
|
44
|
+
const GIT_READ_ACTIONS = [
|
|
45
|
+
"status",
|
|
46
|
+
"log",
|
|
47
|
+
"branches",
|
|
48
|
+
"diff",
|
|
49
|
+
"fileTree",
|
|
50
|
+
"fileContent",
|
|
51
|
+
"commitDetail",
|
|
52
|
+
"mergeRequests",
|
|
53
|
+
"mergeRequestDetail",
|
|
54
|
+
"mergeRequestNotes",
|
|
55
|
+
"pollerStatus",
|
|
56
|
+
"subtreePreview",
|
|
57
|
+
"subtreeOptions"
|
|
58
|
+
];
|
|
59
|
+
const GIT_WRITE_ACTIONS = [
|
|
60
|
+
"clone",
|
|
61
|
+
"pull",
|
|
62
|
+
"push",
|
|
63
|
+
"fetch",
|
|
64
|
+
"checkout",
|
|
65
|
+
"triggerReview",
|
|
66
|
+
"reviewApprovePost",
|
|
67
|
+
"reviewReject",
|
|
68
|
+
"pollNow",
|
|
69
|
+
"subtreeRun"
|
|
70
|
+
];
|
|
71
|
+
function getRepositoryPermissionIds(actions, names) {
|
|
72
|
+
var _a, _b, _c;
|
|
73
|
+
const ids = /* @__PURE__ */ new Set();
|
|
74
|
+
for (const action of actions) {
|
|
75
|
+
const actionData = action.toJSON();
|
|
76
|
+
if (typeof actionData.name !== "string" || !names.includes(actionData.name)) continue;
|
|
77
|
+
const scopeRow = actionData.scope;
|
|
78
|
+
const scope = (scopeRow == null ? void 0 : scopeRow.scope) || scopeRow;
|
|
79
|
+
const scopedIds = (_c = (_b = (_a = scope == null ? void 0 : scope.$and) == null ? void 0 : _a[0]) == null ? void 0 : _b.id) == null ? void 0 : _c.$in;
|
|
80
|
+
if (Array.isArray(scopedIds)) scopedIds.forEach((id) => ids.add(id));
|
|
81
|
+
}
|
|
82
|
+
return [...ids];
|
|
83
|
+
}
|
|
84
|
+
async function syncScopedActions(db, resource, actionNames, ids) {
|
|
85
|
+
const rolesResourceId = getRecordValue(resource, "id");
|
|
86
|
+
const actionsRepo = db.getRepository("rolesResourcesActions");
|
|
87
|
+
for (const storedActionName of actionNames) {
|
|
88
|
+
const action = await actionsRepo.findOne({
|
|
89
|
+
filter: { rolesResourceId, name: storedActionName },
|
|
90
|
+
appends: ["scope"]
|
|
91
|
+
});
|
|
92
|
+
if (ids.length === 0) {
|
|
93
|
+
if (action) await action.destroy();
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const scopeJson = { $and: [{ id: { $in: ids } }] };
|
|
97
|
+
if (action) {
|
|
98
|
+
const actionData = action.toJSON();
|
|
99
|
+
const actionScopeId = getRecordValue(actionData.scope, "id") || actionData.scopeId || getRecordValue(action, "scopeId");
|
|
100
|
+
if (actionScopeId) {
|
|
101
|
+
await db.getRepository("rolesResourcesScopes").update({
|
|
102
|
+
filterByTk: actionScopeId,
|
|
103
|
+
values: { scope: scopeJson }
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
const newScope = await db.getRepository("rolesResourcesScopes").create({ values: { scope: scopeJson } });
|
|
107
|
+
await action.update({ scopeId: getRecordValue(newScope, "id") });
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
const newScope = await db.getRepository("rolesResourcesScopes").create({ values: { scope: scopeJson } });
|
|
111
|
+
await actionsRepo.create({
|
|
112
|
+
values: { rolesResourceId, name: storedActionName, scopeId: getRecordValue(newScope, "id") }
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
35
116
|
}
|
|
36
117
|
async function rolePermissions(ctx, _next) {
|
|
37
118
|
var _a;
|
|
@@ -53,25 +134,22 @@ async function rolePermissions(ctx, _next) {
|
|
|
53
134
|
filter: { rolesResourceId: getRecordValue(resource, "id") },
|
|
54
135
|
appends: ["scope"]
|
|
55
136
|
});
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
137
|
+
const gitManagerResource = await ctx.db.getRepository("rolesResources").findOne({
|
|
138
|
+
filter: { roleName, name: "gitManager" }
|
|
139
|
+
});
|
|
140
|
+
const gitManagerActions = gitManagerResource ? await ctx.db.getRepository("rolesResourcesActions").find({
|
|
141
|
+
filter: { rolesResourceId: getRecordValue(gitManagerResource, "id") },
|
|
142
|
+
appends: ["scope"]
|
|
143
|
+
}) : [];
|
|
144
|
+
const result = {
|
|
145
|
+
read: getRepositoryPermissionIds(actions, [...REPOSITORY_READ_ACTIONS, "read"]),
|
|
146
|
+
write: [
|
|
147
|
+
.../* @__PURE__ */ new Set([
|
|
148
|
+
...getRepositoryPermissionIds(gitManagerActions, GIT_WRITE_ACTIONS),
|
|
149
|
+
...getRepositoryPermissionIds(actions, ["write"])
|
|
150
|
+
])
|
|
151
|
+
]
|
|
152
|
+
};
|
|
75
153
|
ctx.body = result;
|
|
76
154
|
}
|
|
77
155
|
async function updateRolePermissions(ctx, _next) {
|
|
@@ -94,45 +172,32 @@ async function updateRolePermissions(ctx, _next) {
|
|
|
94
172
|
} else if (!getRecordValue(resource, "usingActionsConfig")) {
|
|
95
173
|
await resource.update({ usingActionsConfig: true });
|
|
96
174
|
}
|
|
97
|
-
const rolesResourceId = getRecordValue(resource, "id");
|
|
98
175
|
const actionsRepo = ctx.db.getRepository("rolesResourcesActions");
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
176
|
+
const readIds = permissions.read || [];
|
|
177
|
+
const writeIds = permissions.write || [];
|
|
178
|
+
const effectiveReadIds = [.../* @__PURE__ */ new Set([...readIds, ...writeIds])];
|
|
179
|
+
await syncScopedActions(ctx.db, resource, REPOSITORY_READ_ACTIONS, effectiveReadIds);
|
|
180
|
+
let gitManagerResource = await resourceRepo.findOne({ filter: { roleName, name: "gitManager" } });
|
|
181
|
+
if (!gitManagerResource) {
|
|
182
|
+
gitManagerResource = await resourceRepo.create({
|
|
183
|
+
values: { roleName, name: "gitManager", usingActionsConfig: true }
|
|
104
184
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
} else {
|
|
108
|
-
const scopeJson = { $and: [{ id: { $in: ids } }] };
|
|
109
|
-
if (action) {
|
|
110
|
-
const actionData = action.toJSON ? action.toJSON() : action;
|
|
111
|
-
const actionScope = actionData.scope;
|
|
112
|
-
const actionScopeId = getRecordValue(actionScope, "id") || actionData.scopeId || getRecordValue(action, "scopeId");
|
|
113
|
-
if (actionScopeId) {
|
|
114
|
-
await ctx.db.getRepository("rolesResourcesScopes").update({
|
|
115
|
-
filterByTk: actionScopeId,
|
|
116
|
-
values: { scope: scopeJson }
|
|
117
|
-
});
|
|
118
|
-
} else {
|
|
119
|
-
const newScope = await ctx.db.getRepository("rolesResourcesScopes").create({
|
|
120
|
-
values: { scope: scopeJson }
|
|
121
|
-
});
|
|
122
|
-
await action.update({ scopeId: getRecordValue(newScope, "id") });
|
|
123
|
-
}
|
|
124
|
-
} else {
|
|
125
|
-
const newScope = await ctx.db.getRepository("rolesResourcesScopes").create({
|
|
126
|
-
values: { scope: scopeJson }
|
|
127
|
-
});
|
|
128
|
-
await actionsRepo.create({
|
|
129
|
-
values: { rolesResourceId, name: actionName, scopeId: getRecordValue(newScope, "id") }
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
185
|
+
} else if (!getRecordValue(gitManagerResource, "usingActionsConfig")) {
|
|
186
|
+
await gitManagerResource.update({ usingActionsConfig: true });
|
|
133
187
|
}
|
|
188
|
+
await syncScopedActions(ctx.db, gitManagerResource, GIT_READ_ACTIONS, effectiveReadIds);
|
|
189
|
+
await syncScopedActions(ctx.db, gitManagerResource, GIT_WRITE_ACTIONS, writeIds);
|
|
190
|
+
const legacyReadAction = await actionsRepo.findOne({
|
|
191
|
+
filter: { rolesResourceId: getRecordValue(resource, "id"), name: "read" }
|
|
192
|
+
});
|
|
193
|
+
if (legacyReadAction) await legacyReadAction.destroy();
|
|
194
|
+
const legacyWriteAction = await actionsRepo.findOne({
|
|
195
|
+
filter: { rolesResourceId: getRecordValue(resource, "id"), name: "write" }
|
|
196
|
+
});
|
|
197
|
+
if (legacyWriteAction) await legacyWriteAction.destroy();
|
|
134
198
|
try {
|
|
135
199
|
await resource.writeToACL({ acl: ctx.app.acl });
|
|
200
|
+
await gitManagerResource.writeToACL({ acl: ctx.app.acl });
|
|
136
201
|
} catch (e) {
|
|
137
202
|
(_c = (_b = ctx.logger) == null ? void 0 : _b.warn) == null ? void 0 : _c.call(_b, "[git-manager] Failed to write resource to ACL memory cache:", e);
|
|
138
203
|
}
|
|
@@ -140,6 +205,11 @@ async function updateRolePermissions(ctx, _next) {
|
|
|
140
205
|
}
|
|
141
206
|
// Annotate the CommonJS export names for ESM import in node:
|
|
142
207
|
0 && (module.exports = {
|
|
208
|
+
GIT_READ_ACTIONS,
|
|
209
|
+
GIT_WRITE_ACTIONS,
|
|
210
|
+
REPOSITORY_READ_ACTIONS,
|
|
211
|
+
getRepositoryPermissionIds,
|
|
143
212
|
rolePermissions,
|
|
213
|
+
syncScopedActions,
|
|
144
214
|
updateRolePermissions
|
|
145
215
|
});
|
|
@@ -88,6 +88,14 @@ var gitRepositories_default = (0, import_database.defineCollection)({
|
|
|
88
88
|
interface: "checkbox",
|
|
89
89
|
uiSchema: { title: "Auto Review", type: "boolean", "x-component": "Checkbox" }
|
|
90
90
|
},
|
|
91
|
+
{
|
|
92
|
+
type: "boolean",
|
|
93
|
+
name: "registryExportEnabled",
|
|
94
|
+
allowNull: false,
|
|
95
|
+
defaultValue: false,
|
|
96
|
+
interface: "checkbox",
|
|
97
|
+
uiSchema: { title: "Allow Skill Registry export", type: "boolean", "x-component": "Checkbox" }
|
|
98
|
+
},
|
|
91
99
|
{
|
|
92
100
|
type: "belongsTo",
|
|
93
101
|
name: "autoReviewFlow",
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var migrate_legacy_repository_permissions_exports = {};
|
|
28
|
+
__export(migrate_legacy_repository_permissions_exports, {
|
|
29
|
+
default: () => MigrateLegacyRepositoryPermissions
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(migrate_legacy_repository_permissions_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
var import_role_permissions = require("../actions/role-permissions");
|
|
34
|
+
function getRecordValue(record, key) {
|
|
35
|
+
if (!record || typeof record !== "object") return void 0;
|
|
36
|
+
const model = record;
|
|
37
|
+
return typeof model.get === "function" ? model.get(key) : model[key];
|
|
38
|
+
}
|
|
39
|
+
class MigrateLegacyRepositoryPermissions extends import_server.Migration {
|
|
40
|
+
on = "afterLoad";
|
|
41
|
+
async up() {
|
|
42
|
+
const resourceRepo = this.db.getRepository("rolesResources");
|
|
43
|
+
const actionsRepo = this.db.getRepository("rolesResourcesActions");
|
|
44
|
+
const repositoryResources = await resourceRepo.find({ filter: { name: "gitRepositories" } });
|
|
45
|
+
for (const repositoryResource of repositoryResources) {
|
|
46
|
+
const rolesResourceId = getRecordValue(repositoryResource, "id");
|
|
47
|
+
const roleName = getRecordValue(repositoryResource, "roleName");
|
|
48
|
+
if (!rolesResourceId || !roleName) continue;
|
|
49
|
+
const actions = await actionsRepo.find({
|
|
50
|
+
filter: { rolesResourceId },
|
|
51
|
+
appends: ["scope"]
|
|
52
|
+
});
|
|
53
|
+
const legacyRead = actions.filter((action) => getRecordValue(action, "name") === "read");
|
|
54
|
+
const legacyWrite = actions.filter((action) => getRecordValue(action, "name") === "write");
|
|
55
|
+
if (legacyRead.length === 0 && legacyWrite.length === 0) continue;
|
|
56
|
+
const readIds = (0, import_role_permissions.getRepositoryPermissionIds)(legacyRead, ["read"]);
|
|
57
|
+
const writeIds = (0, import_role_permissions.getRepositoryPermissionIds)(legacyWrite, ["write"]);
|
|
58
|
+
const effectiveReadIds = [.../* @__PURE__ */ new Set([...readIds, ...writeIds])];
|
|
59
|
+
if (effectiveReadIds.length === 0 && writeIds.length === 0) continue;
|
|
60
|
+
await (0, import_role_permissions.syncScopedActions)(this.db, repositoryResource, import_role_permissions.REPOSITORY_READ_ACTIONS, effectiveReadIds);
|
|
61
|
+
let gitManagerResource = await resourceRepo.findOne({ filter: { roleName, name: "gitManager" } });
|
|
62
|
+
if (!gitManagerResource) {
|
|
63
|
+
gitManagerResource = await resourceRepo.create({
|
|
64
|
+
values: { roleName, name: "gitManager", usingActionsConfig: true }
|
|
65
|
+
});
|
|
66
|
+
} else if (!getRecordValue(gitManagerResource, "usingActionsConfig")) {
|
|
67
|
+
await gitManagerResource.update({ usingActionsConfig: true });
|
|
68
|
+
}
|
|
69
|
+
await (0, import_role_permissions.syncScopedActions)(this.db, gitManagerResource, import_role_permissions.GIT_READ_ACTIONS, effectiveReadIds);
|
|
70
|
+
await (0, import_role_permissions.syncScopedActions)(this.db, gitManagerResource, import_role_permissions.GIT_WRITE_ACTIONS, writeIds);
|
|
71
|
+
for (const action of [...legacyRead, ...legacyWrite]) {
|
|
72
|
+
await action.destroy();
|
|
73
|
+
}
|
|
74
|
+
await repositoryResource.writeToACL({ acl: this.app.acl });
|
|
75
|
+
await gitManagerResource.writeToACL({ acl: this.app.acl });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
package/dist/server/plugin.js
CHANGED
|
@@ -53,7 +53,13 @@ var subtreeActions = __toESM(require("./actions/subtree"));
|
|
|
53
53
|
var import_review = require("./actions/review");
|
|
54
54
|
var import_ai_tools = require("./ai-tools");
|
|
55
55
|
var import_poller = require("./poller");
|
|
56
|
+
var import_registry_content_service = require("./services/registry-content-service");
|
|
57
|
+
var import_repository_access = require("./repository-access");
|
|
56
58
|
class PluginGitManagerServer extends import_server.Plugin {
|
|
59
|
+
registryContentService;
|
|
60
|
+
async afterAdd() {
|
|
61
|
+
this.registryContentService = new import_registry_content_service.RegistryGitContentService(this.db);
|
|
62
|
+
}
|
|
57
63
|
async beforeLoad() {
|
|
58
64
|
await this.app.db.import({
|
|
59
65
|
directory: (0, import_path.resolve)(__dirname, "collections")
|
|
@@ -101,6 +107,7 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
101
107
|
subtreeReplace: subtreeActions.subtreeRunOnAppProcess
|
|
102
108
|
}
|
|
103
109
|
});
|
|
110
|
+
this.app.resourceManager.use(import_repository_access.enforceRepositoryAccess);
|
|
104
111
|
this.app.use(async (ctx, next) => {
|
|
105
112
|
if (ctx.logger && ctx.logger.warn) {
|
|
106
113
|
const originalWarn = ctx.logger.warn.bind(ctx.logger);
|
|
@@ -210,10 +217,15 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
210
217
|
this.app.acl.registerSnippet({
|
|
211
218
|
name: `pm.${this.name}.manage`,
|
|
212
219
|
actions: [
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
220
|
+
// ACL snippet actions are resource:action patterns; nested snippet names
|
|
221
|
+
// are not expanded by the core snippet manager.
|
|
222
|
+
"gitRepositories:*",
|
|
223
|
+
"gitAccounts:*",
|
|
224
|
+
"gitReviewFlows:*",
|
|
225
|
+
"gitCodeReviews:*",
|
|
226
|
+
"gitSubtreeConfigs:*",
|
|
227
|
+
"gitSubtreeRuns:*",
|
|
228
|
+
"gitManager:*"
|
|
217
229
|
]
|
|
218
230
|
});
|
|
219
231
|
this.app.resourceManager.use(async (ctx, next) => {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var repository_access_exports = {};
|
|
28
|
+
__export(repository_access_exports, {
|
|
29
|
+
enforceRepositoryAccess: () => enforceRepositoryAccess
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(repository_access_exports);
|
|
32
|
+
const REPOSITORY_SCOPED_ACTIONS = /* @__PURE__ */ new Set([
|
|
33
|
+
"clone",
|
|
34
|
+
"pull",
|
|
35
|
+
"push",
|
|
36
|
+
"fetch",
|
|
37
|
+
"diff",
|
|
38
|
+
"status",
|
|
39
|
+
"log",
|
|
40
|
+
"branches",
|
|
41
|
+
"checkout",
|
|
42
|
+
"fileTree",
|
|
43
|
+
"fileContent",
|
|
44
|
+
"commitDetail",
|
|
45
|
+
"mergeRequests",
|
|
46
|
+
"mergeRequestDetail",
|
|
47
|
+
"mergeRequestNotes",
|
|
48
|
+
"triggerReview",
|
|
49
|
+
"pollNow",
|
|
50
|
+
"subtreePreview",
|
|
51
|
+
"subtreeOptions"
|
|
52
|
+
]);
|
|
53
|
+
function scopeIncludesRepository(filter, repositoryId) {
|
|
54
|
+
if (!filter || typeof filter !== "object") return true;
|
|
55
|
+
const scope = filter;
|
|
56
|
+
if (Object.keys(scope).length === 0) return true;
|
|
57
|
+
if (Array.isArray(scope.$and)) {
|
|
58
|
+
return scope.$and.every((condition) => scopeIncludesRepository(condition, repositoryId));
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(scope.$or)) {
|
|
61
|
+
return scope.$or.some((condition) => scopeIncludesRepository(condition, repositoryId));
|
|
62
|
+
}
|
|
63
|
+
const id = scope.id;
|
|
64
|
+
if (id && typeof id === "object") {
|
|
65
|
+
const allowedIds = id.$in;
|
|
66
|
+
return Array.isArray(allowedIds) && allowedIds.some((allowedId) => String(allowedId) === String(repositoryId));
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
async function enforceRepositoryAccess(ctx, next) {
|
|
71
|
+
var _a, _b, _c, _d, _e;
|
|
72
|
+
if (((_a = ctx.action) == null ? void 0 : _a.resourceName) !== "gitManager" || !REPOSITORY_SCOPED_ACTIONS.has((_b = ctx.action) == null ? void 0 : _b.actionName)) {
|
|
73
|
+
return next();
|
|
74
|
+
}
|
|
75
|
+
const repositoryId = (_c = ctx.action.params) == null ? void 0 : _c.repositoryId;
|
|
76
|
+
if (repositoryId == null) return next();
|
|
77
|
+
const roles = Array.isArray((_d = ctx.state) == null ? void 0 : _d.currentRoles) ? ctx.state.currentRoles : [];
|
|
78
|
+
if (roles.includes("root")) return next();
|
|
79
|
+
const permission = await ctx.app.acl.can({
|
|
80
|
+
roles,
|
|
81
|
+
resource: "gitManager",
|
|
82
|
+
action: ctx.action.actionName
|
|
83
|
+
});
|
|
84
|
+
if (!permission || !scopeIncludesRepository((_e = permission.params) == null ? void 0 : _e.filter, repositoryId)) {
|
|
85
|
+
return ctx.throw(403, "Permission denied");
|
|
86
|
+
}
|
|
87
|
+
return next();
|
|
88
|
+
}
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {
|
|
91
|
+
enforceRepositoryAccess
|
|
92
|
+
});
|