adminizer 4.4.0-build.160 → 4.4.0-build.162
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.
|
@@ -21,7 +21,7 @@ export declare class ConfigHelper {
|
|
|
21
21
|
* Get configured `identifierField` from adminpanel configuration.
|
|
22
22
|
*
|
|
23
23
|
* If not configured and model passed try to guess it using `primaryKey` field in model.
|
|
24
|
-
* If system couldn't guess will return 'id
|
|
24
|
+
* If system couldn't guess will return 'id'.
|
|
25
25
|
* Model could be object or just name (string).
|
|
26
26
|
*
|
|
27
27
|
* **Warning** If you will pass record - method will return 'id'
|
|
@@ -46,4 +46,12 @@ export declare class ConfigHelper {
|
|
|
46
46
|
* @returns Normalized field configuration or `false` if the field should be hidden
|
|
47
47
|
*/
|
|
48
48
|
normalizeFieldConfig(adminizer: Adminizer, config: string | boolean | BaseFieldConfig, key: string, modelField: Attribute): false | BaseFieldConfig;
|
|
49
|
+
/**
|
|
50
|
+
* Normalizes the entire adminpanel configuration.
|
|
51
|
+
* Merges custom config with default config and handles normalization.
|
|
52
|
+
*
|
|
53
|
+
* @param config The custom config object
|
|
54
|
+
* @returns The normalized and merged config
|
|
55
|
+
*/
|
|
56
|
+
static normalizeConfig(config: AdminpanelConfig): AdminpanelConfig;
|
|
49
57
|
}
|
package/helpers/configHelper.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getDefaultConfig } from "../system/defaults.js";
|
|
1
2
|
export class ConfigHelper {
|
|
2
3
|
adminizer;
|
|
3
4
|
constructor(adminizer) {
|
|
@@ -20,7 +21,7 @@ export class ConfigHelper {
|
|
|
20
21
|
* Get configured `identifierField` from adminpanel configuration.
|
|
21
22
|
*
|
|
22
23
|
* If not configured and model passed try to guess it using `primaryKey` field in model.
|
|
23
|
-
* If system couldn't guess will return 'id
|
|
24
|
+
* If system couldn't guess will return 'id'.
|
|
24
25
|
* Model could be object or just name (string).
|
|
25
26
|
*
|
|
26
27
|
* **Warning** If you will pass record - method will return 'id'
|
|
@@ -115,6 +116,40 @@ export class ConfigHelper {
|
|
|
115
116
|
}
|
|
116
117
|
return false;
|
|
117
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Normalizes the entire adminpanel configuration.
|
|
121
|
+
* Merges custom config with default config and handles normalization.
|
|
122
|
+
*
|
|
123
|
+
* @param config The custom config object
|
|
124
|
+
* @returns The normalized and merged config
|
|
125
|
+
*/
|
|
126
|
+
static normalizeConfig(config) {
|
|
127
|
+
const defaultConfig = getDefaultConfig();
|
|
128
|
+
const { forms: configForms = {}, ...restConfig } = config;
|
|
129
|
+
const { forms: defaultForms = {}, } = defaultConfig;
|
|
130
|
+
const mergedConfig = {
|
|
131
|
+
...defaultConfig,
|
|
132
|
+
...restConfig,
|
|
133
|
+
models: {
|
|
134
|
+
...defaultConfig.models,
|
|
135
|
+
...config.models
|
|
136
|
+
},
|
|
137
|
+
forms: {
|
|
138
|
+
path: configForms.path ?? defaultForms.path,
|
|
139
|
+
data: {
|
|
140
|
+
...defaultForms.data,
|
|
141
|
+
...configForms.data
|
|
142
|
+
},
|
|
143
|
+
get: configForms.get ?? defaultForms.get,
|
|
144
|
+
set: configForms.set ?? defaultForms.set
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
// Normalize auth config if it's a boolean
|
|
148
|
+
if (typeof mergedConfig.auth === 'boolean') {
|
|
149
|
+
mergedConfig.auth = { enable: mergedConfig.auth };
|
|
150
|
+
}
|
|
151
|
+
return mergedConfig;
|
|
152
|
+
}
|
|
118
153
|
}
|
|
119
154
|
/**
|
|
120
155
|
* function to determine the display field for associations.
|
package/lib/Adminizer.js
CHANGED
|
@@ -157,27 +157,8 @@ export class Adminizer {
|
|
|
157
157
|
if (this.config && Object.keys(this.config).length > 0) {
|
|
158
158
|
throw new Error("Config has already been initialized");
|
|
159
159
|
}
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
const { forms: configForms = {}, ...restConfig } = config;
|
|
163
|
-
const { forms: defaultForms = {}, } = defaultConfig;
|
|
164
|
-
this.config = {
|
|
165
|
-
...defaultConfig,
|
|
166
|
-
...restConfig,
|
|
167
|
-
models: {
|
|
168
|
-
...defaultConfig.models,
|
|
169
|
-
...config.models
|
|
170
|
-
},
|
|
171
|
-
forms: {
|
|
172
|
-
path: configForms.path ?? defaultForms.path,
|
|
173
|
-
data: {
|
|
174
|
-
...defaultForms.data,
|
|
175
|
-
...configForms.data
|
|
176
|
-
},
|
|
177
|
-
get: configForms.get ?? defaultForms.get,
|
|
178
|
-
set: configForms.set ?? defaultForms.set
|
|
179
|
-
}
|
|
180
|
-
};
|
|
160
|
+
// Normalize and merge config
|
|
161
|
+
this.config = ConfigHelper.normalizeConfig(config);
|
|
181
162
|
// Bind cors
|
|
182
163
|
bindCors(this);
|
|
183
164
|
// set cookie parser
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Knex } from "knex";
|
|
2
|
+
/**
|
|
3
|
+
* Creates all system model tables for Adminizer
|
|
4
|
+
* Tables: userap, groupap, mediamanagerap, mediamanagermetaap, mediamanagerassociationsap,
|
|
5
|
+
* notificationap, usernotificationap, navigationap, groupapuserap
|
|
6
|
+
*/
|
|
7
|
+
export declare function up(knex: Knex): Promise<void>;
|
|
8
|
+
export declare function down(knex: Knex): Promise<void>;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates all system model tables for Adminizer
|
|
3
|
+
* Tables: userap, groupap, mediamanagerap, mediamanagermetaap, mediamanagerassociationsap,
|
|
4
|
+
* notificationap, usernotificationap, navigationap, groupapuserap
|
|
5
|
+
*/
|
|
6
|
+
export async function up(knex) {
|
|
7
|
+
// userap
|
|
8
|
+
await knex.schema.createTable("userap", (table) => {
|
|
9
|
+
table.increments("id").primary().notNullable();
|
|
10
|
+
table.string("login").unique();
|
|
11
|
+
table.string("fullName");
|
|
12
|
+
table.string("email");
|
|
13
|
+
table.string("avatar");
|
|
14
|
+
table.string("passwordHashed");
|
|
15
|
+
table.string("timezone");
|
|
16
|
+
table.string("expires");
|
|
17
|
+
table.string("locale");
|
|
18
|
+
table.boolean("isDeleted");
|
|
19
|
+
table.boolean("isActive");
|
|
20
|
+
table.boolean("isAdministrator");
|
|
21
|
+
table.json("widgets");
|
|
22
|
+
table.boolean("isConfirmed");
|
|
23
|
+
table.timestamp("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
24
|
+
table.timestamp("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
25
|
+
});
|
|
26
|
+
// groupap
|
|
27
|
+
await knex.schema.createTable("groupap", (table) => {
|
|
28
|
+
table.increments("id").primary().notNullable();
|
|
29
|
+
table.string("name").unique();
|
|
30
|
+
table.string("description");
|
|
31
|
+
table.json("tokens");
|
|
32
|
+
table.timestamp("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
33
|
+
table.timestamp("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
34
|
+
});
|
|
35
|
+
// mediamanagerap (self-ref via parentId)
|
|
36
|
+
await knex.schema.createTable("mediamanagerap", (table) => {
|
|
37
|
+
table.uuid("id").primary().notNullable().defaultTo(knex.raw("gen_random_uuid()"));
|
|
38
|
+
table.uuid("parentId").nullable().references("id").inTable("mediamanagerap").onDelete("SET NULL");
|
|
39
|
+
table.string("mimeType");
|
|
40
|
+
table.string("path");
|
|
41
|
+
table.integer("size");
|
|
42
|
+
table.string("group");
|
|
43
|
+
table.string("tag");
|
|
44
|
+
table.string("url");
|
|
45
|
+
table.string("filename");
|
|
46
|
+
table.timestamp("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
47
|
+
table.timestamp("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
48
|
+
});
|
|
49
|
+
// mediamanagermetaap (belongsTo mediamanagerap via parentId)
|
|
50
|
+
await knex.schema.createTable("mediamanagermetaap", (table) => {
|
|
51
|
+
table.uuid("id").primary().notNullable().defaultTo(knex.raw("gen_random_uuid()"));
|
|
52
|
+
table.string("key");
|
|
53
|
+
table.json("value");
|
|
54
|
+
table.boolean("isPublic");
|
|
55
|
+
table.uuid("parentId").nullable().references("id").inTable("mediamanagerap").onDelete("SET NULL");
|
|
56
|
+
table.timestamp("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
57
|
+
table.timestamp("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
58
|
+
});
|
|
59
|
+
// mediamanagerassociationsap (belongsTo mediamanagerap via fileId)
|
|
60
|
+
await knex.schema.createTable("mediamanagerassociationsap", (table) => {
|
|
61
|
+
table.uuid("id").primary().notNullable().defaultTo(knex.raw("gen_random_uuid()"));
|
|
62
|
+
table.string("mediaManagerId");
|
|
63
|
+
table.json("model");
|
|
64
|
+
table.json("modelId");
|
|
65
|
+
table.string("widgetName");
|
|
66
|
+
table.integer("sortOrder");
|
|
67
|
+
table.uuid("fileId").nullable().references("id").inTable("mediamanagerap").onDelete("SET NULL");
|
|
68
|
+
table.timestamp("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
69
|
+
table.timestamp("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
70
|
+
});
|
|
71
|
+
// notificationap
|
|
72
|
+
await knex.schema.createTable("notificationap", (table) => {
|
|
73
|
+
table.increments("id").primary().notNullable();
|
|
74
|
+
table.string("title");
|
|
75
|
+
table.string("message");
|
|
76
|
+
table.string("notificationClass");
|
|
77
|
+
table.string("channel");
|
|
78
|
+
table.json("metadata");
|
|
79
|
+
table.timestamp("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
80
|
+
table.timestamp("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
81
|
+
});
|
|
82
|
+
// usernotificationap (FK to notificationap via column notificationIdId)
|
|
83
|
+
await knex.schema.createTable("usernotificationap", (table) => {
|
|
84
|
+
table.increments("id").primary().notNullable();
|
|
85
|
+
table.integer("userId");
|
|
86
|
+
table.integer("notificationIdId").nullable().references("id").inTable("notificationap").onDelete("SET NULL");
|
|
87
|
+
table.boolean("read");
|
|
88
|
+
table.timestamp("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
89
|
+
table.timestamp("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
90
|
+
});
|
|
91
|
+
// navigationap
|
|
92
|
+
await knex.schema.createTable("navigationap", (table) => {
|
|
93
|
+
table.increments("id").primary().notNullable();
|
|
94
|
+
table.string("label").unique();
|
|
95
|
+
table.json("tree");
|
|
96
|
+
table.timestamp("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
97
|
+
table.timestamp("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
98
|
+
});
|
|
99
|
+
// M:N join: GroupAP <-> UserAP via "groupapuserap"
|
|
100
|
+
await knex.schema.createTable("groupapuserap", (table) => {
|
|
101
|
+
table.integer("UserAPId").notNullable().references("id").inTable("userap").onDelete("CASCADE");
|
|
102
|
+
table.integer("GroupAPId").notNullable().references("id").inTable("groupap").onDelete("CASCADE");
|
|
103
|
+
table.timestamp("createdAt").notNullable().defaultTo(knex.fn.now());
|
|
104
|
+
table.timestamp("updatedAt").notNullable().defaultTo(knex.fn.now());
|
|
105
|
+
table.primary(["UserAPId", "GroupAPId"]);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
export async function down(knex) {
|
|
109
|
+
await knex.schema.dropTableIfExists("groupapuserap");
|
|
110
|
+
await knex.schema.dropTableIfExists("usernotificationap");
|
|
111
|
+
await knex.schema.dropTableIfExists("mediamanagermetaap");
|
|
112
|
+
await knex.schema.dropTableIfExists("mediamanagerassociationsap");
|
|
113
|
+
await knex.schema.dropTableIfExists("mediamanagerap");
|
|
114
|
+
await knex.schema.dropTableIfExists("navigationap");
|
|
115
|
+
await knex.schema.dropTableIfExists("notificationap");
|
|
116
|
+
await knex.schema.dropTableIfExists("groupap");
|
|
117
|
+
await knex.schema.dropTableIfExists("userap");
|
|
118
|
+
}
|