adminforth 1.1.35 → 1.1.36
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/index.js +23 -21
- package/index.ts +24 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -645,6 +645,7 @@ class AdminForth {
|
|
|
645
645
|
function interpretResource(adminUser, resource, meta, source) {
|
|
646
646
|
return __awaiter(this, void 0, void 0, function* () {
|
|
647
647
|
var _b;
|
|
648
|
+
const newResource = JSON.parse(JSON.stringify(resource));
|
|
648
649
|
if (process.env.HEAVY_DEBUG) {
|
|
649
650
|
console.log('🪲Interpreting resource', resource.resourceId, source);
|
|
650
651
|
}
|
|
@@ -657,6 +658,7 @@ class AdminForth {
|
|
|
657
658
|
resource.options.allowedActions[key] = yield value({ adminUser, resource, meta, source });
|
|
658
659
|
}
|
|
659
660
|
})));
|
|
661
|
+
return newResource;
|
|
660
662
|
});
|
|
661
663
|
}
|
|
662
664
|
function checkAccess(action, resource) {
|
|
@@ -678,11 +680,11 @@ class AdminForth {
|
|
|
678
680
|
if (this.statuses.dbDiscover !== 'done') {
|
|
679
681
|
return { error: 'Database discovery is still in progress, please try later' };
|
|
680
682
|
}
|
|
681
|
-
const
|
|
682
|
-
if (!
|
|
683
|
+
const configResource = this.config.resources.find((res) => res.resourceId == resourceId);
|
|
684
|
+
if (!configResource) {
|
|
683
685
|
return { error: `Resource ${resourceId} not found` };
|
|
684
686
|
}
|
|
685
|
-
yield interpretResource(adminUser,
|
|
687
|
+
const resource = yield interpretResource(adminUser, configResource, {}, ActionCheckSource.DisplayButtons);
|
|
686
688
|
// exclude "plugins" key
|
|
687
689
|
return { resource: Object.assign(Object.assign({}, resource), { plugins: undefined }) };
|
|
688
690
|
}),
|
|
@@ -702,11 +704,11 @@ class AdminForth {
|
|
|
702
704
|
if (this.statuses.dbDiscover !== 'done') {
|
|
703
705
|
return { error: 'Database discovery is still in progress, please try later' };
|
|
704
706
|
}
|
|
705
|
-
const
|
|
706
|
-
if (!
|
|
707
|
+
const configResource = this.config.resources.find((res) => res.resourceId == resourceId);
|
|
708
|
+
if (!configResource) {
|
|
707
709
|
return { error: `Resource ${resourceId} not found` };
|
|
708
710
|
}
|
|
709
|
-
yield interpretResource(adminUser,
|
|
711
|
+
const resource = yield interpretResource(adminUser, configResource, { requestBody: body }, ActionCheckSource.DisplayButtons);
|
|
710
712
|
const { allowed, error } = checkAccess(source, resource);
|
|
711
713
|
if (!allowed) {
|
|
712
714
|
return { error };
|
|
@@ -901,11 +903,11 @@ class AdminForth {
|
|
|
901
903
|
path: '/create_record',
|
|
902
904
|
handler: (_y) => __awaiter(this, [_y], void 0, function* ({ body, adminUser }) {
|
|
903
905
|
var _z, _0, _1, _2, _3;
|
|
904
|
-
const
|
|
905
|
-
if (!
|
|
906
|
+
const configResource = this.config.resources.find((res) => res.resourceId == body['resourceId']);
|
|
907
|
+
if (!configResource) {
|
|
906
908
|
return { error: `Resource '${body['resourceId']}' not found` };
|
|
907
909
|
}
|
|
908
|
-
yield interpretResource(adminUser,
|
|
910
|
+
const resource = yield interpretResource(adminUser, configResource, { requestBody: body }, ActionCheckSource.CreateRequest);
|
|
909
911
|
const { allowed, error } = checkAccess(AllowedActionsEnum.create, resource);
|
|
910
912
|
if (!allowed) {
|
|
911
913
|
return { error };
|
|
@@ -973,19 +975,19 @@ class AdminForth {
|
|
|
973
975
|
path: '/update_record',
|
|
974
976
|
handler: (_4) => __awaiter(this, [_4], void 0, function* ({ body, adminUser }) {
|
|
975
977
|
var _5, _6, _7, _8;
|
|
976
|
-
const
|
|
977
|
-
if (!
|
|
978
|
+
const configResource = this.config.resources.find((res) => res.resourceId == body['resourceId']);
|
|
979
|
+
if (!configResource) {
|
|
978
980
|
return { error: `Resource '${body['resourceId']}' not found` };
|
|
979
981
|
}
|
|
980
982
|
const recordId = body['recordId'];
|
|
981
|
-
const connector = this.connectors[
|
|
982
|
-
const oldRecord = yield connector.getRecordByPrimaryKey(
|
|
983
|
+
const connector = this.connectors[configResource.dataSource];
|
|
984
|
+
const oldRecord = yield connector.getRecordByPrimaryKey(configResource, recordId);
|
|
983
985
|
if (!oldRecord) {
|
|
984
|
-
const primaryKeyColumn =
|
|
986
|
+
const primaryKeyColumn = configResource.columns.find((col) => col.primaryKey);
|
|
985
987
|
return { error: `Record with ${primaryKeyColumn.name} ${recordId} not found` };
|
|
986
988
|
}
|
|
987
989
|
const record = body['record'];
|
|
988
|
-
yield interpretResource(adminUser,
|
|
990
|
+
const resource = yield interpretResource(adminUser, configResource, { requestBody: body, record, oldRecord }, ActionCheckSource.EditRequest);
|
|
989
991
|
const { allowed, error } = checkAccess(AllowedActionsEnum.edit, resource);
|
|
990
992
|
if (!allowed) {
|
|
991
993
|
return { error };
|
|
@@ -1038,18 +1040,18 @@ class AdminForth {
|
|
|
1038
1040
|
path: '/delete_record',
|
|
1039
1041
|
handler: (_9) => __awaiter(this, [_9], void 0, function* ({ body, adminUser }) {
|
|
1040
1042
|
var _10, _11, _12, _13;
|
|
1041
|
-
const
|
|
1042
|
-
const record = yield this.connectors[
|
|
1043
|
-
if (!
|
|
1043
|
+
const configResource = this.config.resources.find((res) => res.resourceId == body['resourceId']);
|
|
1044
|
+
const record = yield this.connectors[configResource.dataSource].getRecordByPrimaryKey(configResource, body['primaryKey']);
|
|
1045
|
+
if (!configResource) {
|
|
1044
1046
|
return { error: `Resource '${body['resourceId']}' not found` };
|
|
1045
1047
|
}
|
|
1046
1048
|
if (!record) {
|
|
1047
1049
|
return { error: `Record with ${body['primaryKey']} not found` };
|
|
1048
1050
|
}
|
|
1049
|
-
if (
|
|
1050
|
-
return { error: `Resource '${
|
|
1051
|
+
if (configResource.options.allowedActions.delete === false) {
|
|
1052
|
+
return { error: `Resource '${configResource.resourceId}' does not allow delete action` };
|
|
1051
1053
|
}
|
|
1052
|
-
yield interpretResource(adminUser,
|
|
1054
|
+
const resource = yield interpretResource(adminUser, configResource, { requestBody: body }, ActionCheckSource.DeleteRequest);
|
|
1053
1055
|
const { allowed, error } = checkAccess(AllowedActionsEnum.delete, resource);
|
|
1054
1056
|
if (!allowed) {
|
|
1055
1057
|
return { error };
|
package/index.ts
CHANGED
|
@@ -732,7 +732,8 @@ class AdminForth implements AdminForthClass {
|
|
|
732
732
|
},
|
|
733
733
|
});
|
|
734
734
|
|
|
735
|
-
async function interpretResource(adminUser: AdminUser, resource: AdminForthResource, meta: any, source: ActionCheckSource) {
|
|
735
|
+
async function interpretResource(adminUser: AdminUser, resource: AdminForthResource, meta: any, source: ActionCheckSource): Promise<AdminForthResource> {
|
|
736
|
+
const newResource = JSON.parse(JSON.stringify(resource));
|
|
736
737
|
if (process.env.HEAVY_DEBUG) {
|
|
737
738
|
console.log('🪲Interpreting resource', resource.resourceId, source);
|
|
738
739
|
}
|
|
@@ -750,6 +751,7 @@ class AdminForth implements AdminForthClass {
|
|
|
750
751
|
}
|
|
751
752
|
})
|
|
752
753
|
);
|
|
754
|
+
return newResource;
|
|
753
755
|
}
|
|
754
756
|
|
|
755
757
|
function checkAccess(action: AllowedActionsEnum, resource: AdminForthResource): { allowed: boolean, error?: string } {
|
|
@@ -772,12 +774,12 @@ class AdminForth implements AdminForthClass {
|
|
|
772
774
|
if (this.statuses.dbDiscover !== 'done') {
|
|
773
775
|
return { error : 'Database discovery is still in progress, please try later' };
|
|
774
776
|
}
|
|
775
|
-
const
|
|
776
|
-
if (!
|
|
777
|
+
const configResource = this.config.resources.find((res) => res.resourceId == resourceId);
|
|
778
|
+
if (!configResource) {
|
|
777
779
|
return { error: `Resource ${resourceId} not found` };
|
|
778
780
|
}
|
|
779
781
|
|
|
780
|
-
await interpretResource(adminUser,
|
|
782
|
+
const resource = await interpretResource(adminUser, configResource, {}, ActionCheckSource.DisplayButtons);
|
|
781
783
|
|
|
782
784
|
// exclude "plugins" key
|
|
783
785
|
return { resource: { ...resource, plugins: undefined } };
|
|
@@ -797,12 +799,12 @@ class AdminForth implements AdminForthClass {
|
|
|
797
799
|
if (this.statuses.dbDiscover !== 'done') {
|
|
798
800
|
return { error : 'Database discovery is still in progress, please try later' };
|
|
799
801
|
}
|
|
800
|
-
const
|
|
801
|
-
if (!
|
|
802
|
+
const configResource = this.config.resources.find((res) => res.resourceId == resourceId);
|
|
803
|
+
if (!configResource) {
|
|
802
804
|
return { error: `Resource ${resourceId} not found` };
|
|
803
805
|
}
|
|
804
806
|
|
|
805
|
-
await interpretResource(adminUser,
|
|
807
|
+
const resource = await interpretResource(adminUser, configResource, { requestBody: body }, ActionCheckSource.DisplayButtons);
|
|
806
808
|
|
|
807
809
|
const { allowed, error } = checkAccess(source as AllowedActionsEnum, resource);
|
|
808
810
|
if (!allowed) {
|
|
@@ -1022,11 +1024,11 @@ class AdminForth implements AdminForthClass {
|
|
|
1022
1024
|
method: 'POST',
|
|
1023
1025
|
path: '/create_record',
|
|
1024
1026
|
handler: async ({ body, adminUser }) => {
|
|
1025
|
-
const
|
|
1026
|
-
if (!
|
|
1027
|
+
const configResource = this.config.resources.find((res) => res.resourceId == body['resourceId']);
|
|
1028
|
+
if (!configResource) {
|
|
1027
1029
|
return { error: `Resource '${body['resourceId']}' not found` };
|
|
1028
1030
|
}
|
|
1029
|
-
await interpretResource(adminUser,
|
|
1031
|
+
const resource = await interpretResource(adminUser, configResource, { requestBody: body}, ActionCheckSource.CreateRequest);
|
|
1030
1032
|
|
|
1031
1033
|
const { allowed, error } = checkAccess(AllowedActionsEnum.create, resource);
|
|
1032
1034
|
if (!allowed) {
|
|
@@ -1103,21 +1105,21 @@ class AdminForth implements AdminForthClass {
|
|
|
1103
1105
|
method: 'POST',
|
|
1104
1106
|
path: '/update_record',
|
|
1105
1107
|
handler: async ({ body, adminUser }) => {
|
|
1106
|
-
const
|
|
1107
|
-
if (!
|
|
1108
|
+
const configResource = this.config.resources.find((res) => res.resourceId == body['resourceId']);
|
|
1109
|
+
if (!configResource) {
|
|
1108
1110
|
return { error: `Resource '${body['resourceId']}' not found` };
|
|
1109
1111
|
}
|
|
1110
1112
|
|
|
1111
1113
|
const recordId = body['recordId'];
|
|
1112
|
-
const connector = this.connectors[
|
|
1113
|
-
const oldRecord = await connector.getRecordByPrimaryKey(
|
|
1114
|
+
const connector = this.connectors[configResource.dataSource];
|
|
1115
|
+
const oldRecord = await connector.getRecordByPrimaryKey(configResource, recordId)
|
|
1114
1116
|
if (!oldRecord) {
|
|
1115
|
-
const primaryKeyColumn =
|
|
1117
|
+
const primaryKeyColumn = configResource.columns.find((col) => col.primaryKey);
|
|
1116
1118
|
return { error: `Record with ${primaryKeyColumn.name} ${recordId} not found` };
|
|
1117
1119
|
}
|
|
1118
1120
|
const record = body['record'];
|
|
1119
1121
|
|
|
1120
|
-
await interpretResource(adminUser,
|
|
1122
|
+
const resource = await interpretResource(adminUser, configResource, { requestBody: body, record, oldRecord}, ActionCheckSource.EditRequest);
|
|
1121
1123
|
|
|
1122
1124
|
const { allowed, error } = checkAccess(AllowedActionsEnum.edit, resource);
|
|
1123
1125
|
if (!allowed) {
|
|
@@ -1176,19 +1178,19 @@ class AdminForth implements AdminForthClass {
|
|
|
1176
1178
|
method: 'POST',
|
|
1177
1179
|
path: '/delete_record',
|
|
1178
1180
|
handler: async ({ body, adminUser }) => {
|
|
1179
|
-
const
|
|
1180
|
-
const record = await this.connectors[
|
|
1181
|
-
if (!
|
|
1181
|
+
const configResource = this.config.resources.find((res) => res.resourceId == body['resourceId']);
|
|
1182
|
+
const record = await this.connectors[configResource.dataSource].getRecordByPrimaryKey(configResource, body['primaryKey']);
|
|
1183
|
+
if (!configResource) {
|
|
1182
1184
|
return { error: `Resource '${body['resourceId']}' not found` };
|
|
1183
1185
|
}
|
|
1184
1186
|
if (!record){
|
|
1185
1187
|
return { error: `Record with ${body['primaryKey']} not found` };
|
|
1186
1188
|
}
|
|
1187
|
-
if (
|
|
1188
|
-
return { error: `Resource '${
|
|
1189
|
+
if (configResource.options.allowedActions.delete === false) {
|
|
1190
|
+
return { error: `Resource '${configResource.resourceId}' does not allow delete action` };
|
|
1189
1191
|
}
|
|
1190
1192
|
|
|
1191
|
-
await interpretResource(adminUser,
|
|
1193
|
+
const resource = await interpretResource(adminUser, configResource, { requestBody: body }, ActionCheckSource.DeleteRequest);
|
|
1192
1194
|
|
|
1193
1195
|
const { allowed, error } = checkAccess(AllowedActionsEnum.delete, resource);
|
|
1194
1196
|
if (!allowed) {
|