directus-template-cli 0.3.0-beta.6 → 0.3.0-beta.7
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/lib/extract/extract-permissions.d.ts +0 -1
- package/dist/lib/extract/extract-permissions.js +1 -22
- package/dist/lib/extract/index.js +0 -3
- package/dist/lib/load/index.js +10 -4
- package/dist/lib/load/load-permissions.d.ts +1 -0
- package/dist/lib/load/{load-public-permissions.js → load-permissions.js} +5 -1
- package/dist/lib/load/load-users.d.ts +1 -1
- package/dist/lib/load/load-users.js +8 -16
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/templates/agencyos/src/permissions.json +5586 -55
- package/templates/agencyos/src/users.json +5 -5
- package/dist/lib/load/load-public-permissions.d.ts +0 -1
|
@@ -1,35 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractPermissions =
|
|
3
|
+
exports.extractPermissions = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const api_1 = require("../api");
|
|
6
6
|
const write_to_file_1 = tslib_1.__importDefault(require("../utils/write-to-file"));
|
|
7
|
-
async function extractPublicPermissions(dir) {
|
|
8
|
-
try {
|
|
9
|
-
const { data } = await api_1.api.get("permissions", {
|
|
10
|
-
params: {
|
|
11
|
-
limit: "-1",
|
|
12
|
-
"filter[role][_null]": true,
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
// Delete the id field from the permissions so we don't have to reset the autoincrement on the db
|
|
16
|
-
data.data.forEach((permission) => {
|
|
17
|
-
delete permission.id;
|
|
18
|
-
});
|
|
19
|
-
// Write the public permissions to the specified directory
|
|
20
|
-
await (0, write_to_file_1.default)("public-permissions", data.data, dir);
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
console.log("Error fetching public permissions:", error);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.extractPublicPermissions = extractPublicPermissions;
|
|
27
7
|
async function extractPermissions(dir) {
|
|
28
8
|
try {
|
|
29
9
|
const { data } = await api_1.api.get("permissions", {
|
|
30
10
|
params: {
|
|
31
11
|
limit: "-1",
|
|
32
|
-
"filter[role][_null]": true,
|
|
33
12
|
},
|
|
34
13
|
});
|
|
35
14
|
// Delete the id field from the permissions so we don't have to reset the autoincrement on the db
|
|
@@ -42,13 +42,10 @@ async function extract(dir, cli) {
|
|
|
42
42
|
await (0, extract_files_1.default)(destination);
|
|
43
43
|
await (0, extract_presets_1.default)(destination);
|
|
44
44
|
await (0, extract_permissions_1.extractPermissions)(destination);
|
|
45
|
-
await (0, extract_permissions_1.extractPermissions)(destination);
|
|
46
45
|
// Iterate through the endpoints
|
|
47
46
|
for (const endpoint of endpoints) {
|
|
48
47
|
await (0, extract_from_endpoint_1.default)(endpoint, destination);
|
|
49
48
|
}
|
|
50
|
-
// Extract public permissions
|
|
51
|
-
await (0, extract_permissions_1.extractPublicPermissions)(destination);
|
|
52
49
|
// Extract content
|
|
53
50
|
await (0, extract_content_1.extractContent)(destination);
|
|
54
51
|
// Extract assets
|
package/dist/lib/load/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
const api_1 = require("../api");
|
|
4
5
|
const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
|
|
5
6
|
const load_to_destination_1 = tslib_1.__importDefault(require("../utils/load-to-destination"));
|
|
6
7
|
const load_schema_1 = tslib_1.__importDefault(require("./load-schema"));
|
|
@@ -14,18 +15,23 @@ const load_operations_1 = tslib_1.__importDefault(require("./load-operations"));
|
|
|
14
15
|
const load_data_1 = tslib_1.__importDefault(require("./load-data"));
|
|
15
16
|
const load_presets_1 = tslib_1.__importDefault(require("./load-presets"));
|
|
16
17
|
const load_settings_1 = tslib_1.__importDefault(require("./load-settings"));
|
|
17
|
-
const
|
|
18
|
+
const load_permissions_1 = require("./load-permissions");
|
|
18
19
|
async function apply(dir, cli) {
|
|
19
20
|
// Get the source directory for the actual files
|
|
20
21
|
const source = dir + "/src";
|
|
21
22
|
// Load the template files into the destination
|
|
22
23
|
await (0, load_schema_1.default)(source + "/schema");
|
|
23
24
|
cli.log("Loaded Schema");
|
|
24
|
-
|
|
25
|
+
// Role Loading Logic
|
|
26
|
+
const roles = (0, read_file_1.default)("roles", source);
|
|
27
|
+
const legacyAdminRoleId = roles.find((role) => role.name === "Administrator").id;
|
|
28
|
+
const currentUser = await api_1.api.get("users/me");
|
|
29
|
+
const newAdminRoleId = currentUser.data.data.role;
|
|
30
|
+
await (0, load_roles_1.default)(roles);
|
|
25
31
|
cli.log("Loaded Roles");
|
|
26
32
|
await (0, load_files_1.default)((0, read_file_1.default)("files", source), source); // Comes after folders
|
|
27
33
|
cli.log("Loaded Files");
|
|
28
|
-
await (0, load_users_1.default)((0, read_file_1.default)("users", source)); // Comes after roles, files
|
|
34
|
+
await (0, load_users_1.default)((0, read_file_1.default)("users", source), legacyAdminRoleId, newAdminRoleId); // Comes after roles, files
|
|
29
35
|
cli.log("Loaded Users");
|
|
30
36
|
await (0, load_folders_1.default)(source);
|
|
31
37
|
cli.log("Loaded Folders");
|
|
@@ -44,7 +50,7 @@ async function apply(dir, cli) {
|
|
|
44
50
|
cli.log("Loaded Presets");
|
|
45
51
|
await (0, load_settings_1.default)((0, read_file_1.default)("settings", source));
|
|
46
52
|
cli.log("Loaded Settings");
|
|
47
|
-
await (0,
|
|
53
|
+
await (0, load_permissions_1.loadPermissions)((0, read_file_1.default)("permissions", source), legacyAdminRoleId, newAdminRoleId);
|
|
48
54
|
cli.log("Loaded Permissions");
|
|
49
55
|
return {};
|
|
50
56
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadPermissions(permissions: any, legacyAdminRoleId: string | number, newAdminRoleId: string | number): Promise<void>;
|
|
@@ -14,8 +14,12 @@ async function removeallPublicPermissions() {
|
|
|
14
14
|
data: ids,
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
const clearAdminPermissions = (permissions, legacyAdminRoleId) => {
|
|
18
|
+
return permissions.filter((permission) => permission.role !== legacyAdminRoleId);
|
|
19
|
+
};
|
|
20
|
+
async function loadPermissions(permissions, legacyAdminRoleId, newAdminRoleId) {
|
|
18
21
|
await removeallPublicPermissions();
|
|
22
|
+
permissions = clearAdminPermissions(permissions, legacyAdminRoleId);
|
|
19
23
|
await (0, load_to_destination_1.default)("permissions", permissions);
|
|
20
24
|
}
|
|
21
25
|
exports.loadPermissions = loadPermissions;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: (users: any[]) => Promise<void>;
|
|
1
|
+
declare const _default: (users: any[], legacyAdminRoleId: string | number, newAdminRoleId: string | number) => Promise<void>;
|
|
2
2
|
export default _default;
|
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
3
|
const api_1 = require("../api");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
//
|
|
4
|
+
exports.default = async (users, legacyAdminRoleId, newAdminRoleId) => {
|
|
5
|
+
const cleanedUpUsers = users.map((user) => {
|
|
6
|
+
// If the user is an admin, we need to change their role to the new admin role
|
|
7
|
+
const isAdmin = user.role === legacyAdminRoleId;
|
|
8
|
+
user.role = isAdmin ? newAdminRoleId : user.role;
|
|
9
|
+
// Delete the unneeded fields
|
|
11
10
|
delete user.last_page;
|
|
12
11
|
delete user.token;
|
|
13
|
-
// user.password = getNewPassword()
|
|
14
12
|
return user;
|
|
15
13
|
});
|
|
16
14
|
for (const user of cleanedUpUsers) {
|
|
17
15
|
try {
|
|
18
|
-
await api_1.api.post(
|
|
16
|
+
await api_1.api.post("users", user);
|
|
19
17
|
// console.log('Uploaded User' + user.email)
|
|
20
18
|
}
|
|
21
19
|
catch (error) {
|
|
22
|
-
console.log(
|
|
20
|
+
console.log("Error uploading user.", error.response.data.errors);
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
23
|
};
|
|
26
|
-
const getNewPassword = () => {
|
|
27
|
-
return generate_password_1.default.generate({
|
|
28
|
-
length: 12,
|
|
29
|
-
numbers: true,
|
|
30
|
-
});
|
|
31
|
-
};
|
package/oclif.manifest.json
CHANGED