Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# codbex-contracts

### Model
<img width="791" alt="Screenshot 2025-01-03 at 19 58 47" src="https://github.com/user-attachments/assets/a1e50b7b-7573-4efe-b151-991abc93f4cd" />

![model](images/contracts-model.png)


18 changes: 9 additions & 9 deletions codbex-contracts/codbex-contracts.edm

Large diffs are not rendered by default.

49 changes: 47 additions & 2 deletions codbex-contracts/codbex-contracts.gen
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@
"fileName": "codbex-contracts",
"genFolderName": "codbex-contracts",
"dataSource": "DefaultDB",
"roles": [
{
"entityName": "Contract",
"roleRead": "codbex-contracts.Contract.ContractReadOnly",
"roleWrite": "codbex-contracts.Contract.ContractFullAccess"
},
{
"entityName": "ContractType",
"roleRead": "codbex-contracts.Settings.ContractTypeReadOnly",
"roleWrite": "codbex-contracts.Settings.ContractTypeFullAccess"
},
{
"entityName": "EmployeeContract",
"roleRead": "codbex-contracts.EmployeeContracts.EmployeeContractReadOnly",
"roleWrite": "codbex-contracts.EmployeeContracts.EmployeeContractFullAccess"
},
{
"entityName": "EmployeeContractItem",
"roleRead": "codbex-contracts.EmployeeContracts.EmployeeContractItemReadOnly",
"roleWrite": "codbex-contracts.EmployeeContracts.EmployeeContractItemFullAccess"
}
],
"projectName": "codbex-contracts",
"workspaceName": "workspace",
"filePath": "codbex-contracts.model",
Expand All @@ -33,6 +55,10 @@
"Contract-details",
"Contract-details",
"Contract-details",
"Contract-details",
"Contract-details",
"Contract-details",
"Contract-details",
"Contract-details"
],
"name": "Contract",
Expand Down Expand Up @@ -84,6 +110,10 @@
"EmployeeContract-details",
"EmployeeContract-details",
"EmployeeContract-details",
"EmployeeContract-details",
"EmployeeContract-details",
"EmployeeContract-details",
"EmployeeContract-details",
"EmployeeContract-details"
],
"name": "EmployeeContracts",
Expand Down Expand Up @@ -235,7 +265,7 @@
},
{
"dataLength": "500",
"dataName": "CONTRACT_URL",
"dataName": "CONTRACT_DOCUMENT",
"dataNullable": true,
"dataType": "VARCHAR",
"description": "",
Expand Down Expand Up @@ -322,6 +352,7 @@
"description": "Manage entity Contract",
"feedPassword": "YWRtaW4=",
"feedUsername": "YWRtaW4=",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"importsCode": "import { NumberGeneratorService } from \"/codbex-number-generator/service/generator\";",
Expand All @@ -336,6 +367,8 @@
"perspectiveName": "Contract",
"perspectiveOrder": "100",
"perspectiveRole": "",
"roleRead": "codbex-contracts.Contract.ContractReadOnly",
"roleWrite": "codbex-contracts.Contract.ContractFullAccess",
"title": "Contract",
"tooltip": "Contract",
"type": "PRIMARY",
Expand Down Expand Up @@ -459,7 +492,7 @@
},
{
"dataLength": "500",
"dataName": "CONTRACT_URL",
"dataName": "CONTRACT_DOCUMENT",
"dataNullable": true,
"dataType": "VARCHAR",
"description": "",
Expand Down Expand Up @@ -602,6 +635,7 @@
"description": "Manage entity ContractType",
"feedPassword": "YWRtaW4=",
"feedUsername": "YWRtaW4=",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE",
Expand All @@ -615,6 +649,8 @@
"perspectiveName": "Settings",
"perspectiveOrder": "999",
"perspectiveRole": "",
"roleRead": "codbex-contracts.Settings.ContractTypeReadOnly",
"roleWrite": "codbex-contracts.Settings.ContractTypeFullAccess",
"title": "ContractType",
"tooltip": "ContractType",
"type": "SETTING",
Expand Down Expand Up @@ -940,6 +976,7 @@
"dataName": "COMPANY",
"dataQuery": "",
"description": "Manage entity Company",
"generateDefaultRoles": "false",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE",
Expand Down Expand Up @@ -1051,6 +1088,7 @@
"dataName": "JOBROLE",
"dataQuery": "",
"description": "Manage entity JobRole",
"generateDefaultRoles": "false",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE",
Expand Down Expand Up @@ -1374,6 +1412,7 @@
"dataName": "EMPLOYEECONTRACT",
"dataQuery": "",
"description": "Manage entity EmployeeContract",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"importsCode": "import { NumberGeneratorService } from \"/codbex-number-generator/service/generator\";",
Expand All @@ -1388,6 +1427,8 @@
"perspectiveName": "EmployeeContracts",
"perspectiveOrder": "103",
"perspectiveRole": "",
"roleRead": "codbex-contracts.EmployeeContracts.EmployeeContractReadOnly",
"roleWrite": "codbex-contracts.EmployeeContracts.EmployeeContractFullAccess",
"title": "EmployeeContract",
"tooltip": "EmployeeContract",
"type": "PRIMARY",
Expand Down Expand Up @@ -1798,6 +1839,7 @@
"dataName": "EMPLOYEECONTRACTITEM",
"dataQuery": "",
"description": "Manage entity EmployeeContractItem",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE_DETAILS",
Expand All @@ -1811,6 +1853,8 @@
"perspectiveName": "EmployeeContracts",
"perspectiveOrder": "103",
"perspectiveRole": "",
"roleRead": "codbex-contracts.EmployeeContracts.EmployeeContractItemReadOnly",
"roleWrite": "codbex-contracts.EmployeeContracts.EmployeeContractItemFullAccess",
"title": "EmployeeContractItem",
"tooltip": "EmployeeContractItem",
"type": "DEPENDENT",
Expand Down Expand Up @@ -2122,6 +2166,7 @@
"dataName": "EMPLOYEE",
"dataQuery": "",
"description": "Manage entity Employee",
"generateDefaultRoles": "false",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE",
Expand Down
17 changes: 16 additions & 1 deletion codbex-contracts/codbex-contracts.model
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
},
{
"dataLength": "500",
"dataName": "CONTRACT_URL",
"dataName": "CONTRACT_DOCUMENT",
"dataNullable": "true",
"dataType": "VARCHAR",
"description": "",
Expand Down Expand Up @@ -130,6 +130,7 @@
"description": "Manage entity Contract",
"feedPassword": "YWRtaW4=",
"feedUsername": "YWRtaW4=",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"importsCode": "aW1wb3J0IHsgTnVtYmVyR2VuZXJhdG9yU2VydmljZSB9IGZyb20gIi9jb2RiZXgtbnVtYmVyLWdlbmVyYXRvci9zZXJ2aWNlL2dlbmVyYXRvciI7",
Expand All @@ -144,6 +145,8 @@
"perspectiveName": "Contract",
"perspectiveOrder": "100",
"perspectiveRole": "",
"roleRead": "codbex-contracts.Contract.ContractReadOnly",
"roleWrite": "codbex-contracts.Contract.ContractFullAccess",
"title": "Contract",
"tooltip": "Contract",
"type": "PRIMARY"
Expand Down Expand Up @@ -185,6 +188,7 @@
"description": "Manage entity ContractType",
"feedPassword": "YWRtaW4=",
"feedUsername": "YWRtaW4=",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE",
Expand All @@ -198,6 +202,8 @@
"perspectiveName": "Settings",
"perspectiveOrder": "999",
"perspectiveRole": "",
"roleRead": "codbex-contracts.Settings.ContractTypeReadOnly",
"roleWrite": "codbex-contracts.Settings.ContractTypeFullAccess",
"title": "ContractType",
"tooltip": "ContractType",
"type": "SETTING"
Expand Down Expand Up @@ -388,6 +394,7 @@
"dataName": "COMPANY",
"dataQuery": "",
"description": "Manage entity Company",
"generateDefaultRoles": "false",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE",
Expand Down Expand Up @@ -459,6 +466,7 @@
"dataName": "JOBROLE",
"dataQuery": "",
"description": "Manage entity JobRole",
"generateDefaultRoles": "false",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE",
Expand Down Expand Up @@ -657,6 +665,7 @@
"dataName": "EMPLOYEECONTRACT",
"dataQuery": "",
"description": "Manage entity EmployeeContract",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"importsCode": "aW1wb3J0IHsgTnVtYmVyR2VuZXJhdG9yU2VydmljZSB9IGZyb20gIi9jb2RiZXgtbnVtYmVyLWdlbmVyYXRvci9zZXJ2aWNlL2dlbmVyYXRvciI7",
Expand All @@ -671,6 +680,8 @@
"perspectiveName": "EmployeeContracts",
"perspectiveOrder": "103",
"perspectiveRole": "",
"roleRead": "codbex-contracts.EmployeeContracts.EmployeeContractReadOnly",
"roleWrite": "codbex-contracts.EmployeeContracts.EmployeeContractFullAccess",
"title": "EmployeeContract",
"tooltip": "EmployeeContract",
"type": "PRIMARY"
Expand Down Expand Up @@ -742,6 +753,7 @@
"dataName": "EMPLOYEECONTRACTITEM",
"dataQuery": "",
"description": "Manage entity EmployeeContractItem",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE_DETAILS",
Expand All @@ -755,6 +767,8 @@
"perspectiveName": "EmployeeContracts",
"perspectiveOrder": "103",
"perspectiveRole": "",
"roleRead": "codbex-contracts.EmployeeContracts.EmployeeContractItemReadOnly",
"roleWrite": "codbex-contracts.EmployeeContracts.EmployeeContractItemFullAccess",
"title": "EmployeeContractItem",
"tooltip": "EmployeeContractItem",
"type": "DEPENDENT"
Expand Down Expand Up @@ -938,6 +952,7 @@
"dataName": "EMPLOYEE",
"dataQuery": "",
"description": "Manage entity Employee",
"generateDefaultRoles": "false",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"module": "codbex-contracts/events/EmployeeContractItem/EmployeeContractItemToRecordHandler.ts",
"extensionPoint": "codbex-contracts-EmployeeContracts-EmployeeContract",
"description": "Employee contract Extension"
"description": "Employee contract Extension",
"role": ""
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Controller, Get, Post, Put, Delete, response } from "sdk/http"
import { Extensions } from "sdk/extensions"
import { ContractRepository, ContractEntityOptions } from "../../dao/Contract/ContractRepository";
import { user } from "sdk/security"
import { ForbiddenError } from "../utils/ForbiddenError";
import { ValidationError } from "../utils/ValidationError";
import { HttpUtils } from "../utils/HttpUtils";
// custom imports
Expand All @@ -16,6 +18,7 @@ class ContractService {
@Get("/")
public getAll(_: any, ctx: any) {
try {
this.checkPermissions("read");
const options: ContractEntityOptions = {
$limit: ctx.queryParameters["$limit"] ? parseInt(ctx.queryParameters["$limit"]) : undefined,
$offset: ctx.queryParameters["$offset"] ? parseInt(ctx.queryParameters["$offset"]) : undefined
Expand All @@ -30,6 +33,7 @@ class ContractService {
@Post("/")
public create(entity: any) {
try {
this.checkPermissions("write");
this.validateEntity(entity);
entity.Id = this.repository.create(entity);
response.setHeader("Content-Location", "/services/ts/codbex-contracts/gen/codbex-contracts/api/Contract/ContractService.ts/" + entity.Id);
Expand All @@ -43,6 +47,7 @@ class ContractService {
@Get("/count")
public count() {
try {
this.checkPermissions("read");
return this.repository.count();
} catch (error: any) {
this.handleError(error);
Expand All @@ -52,6 +57,7 @@ class ContractService {
@Post("/count")
public countWithFilter(filter: any) {
try {
this.checkPermissions("read");
return this.repository.count(filter);
} catch (error: any) {
this.handleError(error);
Expand All @@ -61,6 +67,7 @@ class ContractService {
@Post("/search")
public search(filter: any) {
try {
this.checkPermissions("read");
return this.repository.findAll(filter);
} catch (error: any) {
this.handleError(error);
Expand All @@ -70,6 +77,7 @@ class ContractService {
@Get("/:id")
public getById(_: any, ctx: any) {
try {
this.checkPermissions("read");
const id = parseInt(ctx.pathParameters.id);
const entity = this.repository.findById(id);
if (entity) {
Expand All @@ -85,6 +93,7 @@ class ContractService {
@Put("/:id")
public update(entity: any, ctx: any) {
try {
this.checkPermissions("write");
entity.Id = ctx.pathParameters.id;
this.validateEntity(entity);
this.repository.update(entity);
Expand All @@ -97,6 +106,7 @@ class ContractService {
@Delete("/:id")
public deleteById(_: any, ctx: any) {
try {
this.checkPermissions("write");
const id = ctx.pathParameters.id;
const entity = this.repository.findById(id);
if (entity) {
Expand All @@ -120,6 +130,15 @@ class ContractService {
}
}

private checkPermissions(operationType: string) {
if (operationType === "read" && !(user.isInRole("codbex-contracts.Contract.ContractReadOnly") || user.isInRole("codbex-contracts.Contract.ContractFullAccess"))) {
throw new ForbiddenError();
}
if (operationType === "write" && !user.isInRole("codbex-contracts.Contract.ContractFullAccess")) {
throw new ForbiddenError();
}
}

private validateEntity(entity: any): void {
if (entity.Number?.length > 20) {
throw new ValidationError(`The 'Number' exceeds the maximum length of [20] characters`);
Expand Down
Loading