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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# codbex-methods
# codbex-methods

Methods Management Application

### Model

![model](images/methods-model.png)
6 changes: 3 additions & 3 deletions codbex-methods/codbex-methods.edm
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<model>
<entities>
<entity name="PaymentMethod" dataName="PAYMENTMETHOD" dataCount="SELECT COUNT(*) AS COUNT FROM &quot;${tablePrefix}PAYMENTMETHOD&quot;" dataQuery="" type="SETTING" title="PaymentMethod" caption="Manage entity PaymentMethod" description="Manage entity PaymentMethod" tooltip="PaymentMethod" icon="/services/web/resources/unicons/file.svg" menuKey="paymentmethod" menuLabel="PaymentMethod" menuIndex="100" layoutType="MANAGE" navigationPath="/Home" perspectiveName="PaymentMethod" perspectiveLabel="PaymentMethod" perspectiveIcon="/services/web/resources/unicons/archive.svg" perspectiveOrder="100" perspectiveRole="" generateReport="false" generateDefaultRoles="false">
<entity name="PaymentMethod" dataName="PAYMENTMETHOD" dataCount="SELECT COUNT(*) AS COUNT FROM &quot;${tablePrefix}PAYMENTMETHOD&quot;" dataQuery="" type="SETTING" title="PaymentMethod" caption="Manage entity PaymentMethod" description="Manage entity PaymentMethod" tooltip="PaymentMethod" icon="/services/web/resources/unicons/file.svg" menuKey="paymentmethod" menuLabel="PaymentMethod" menuIndex="100" layoutType="MANAGE" navigationPath="/Home" perspectiveName="PaymentMethod" perspectiveLabel="PaymentMethod" perspectiveIcon="/services/web/resources/unicons/archive.svg" perspectiveOrder="100" perspectiveRole="" generateReport="false" generateDefaultRoles="true" roleRead="codbex-methods.PaymentMethod.PaymentMethodReadOnly" roleWrite="codbex-methods.PaymentMethod.PaymentMethodFullAccess">
<property name="Id" description="" tooltip="" dataName="PAYMENTMETHOD_ID" dataType="INTEGER" dataNullable="true" dataPrimaryKey="true" dataAutoIncrement="true" widgetType="TEXTBOX" widgetSize="" widgetLength="20" widgetIsMajor="true"></property>
<property name="Name" description="" tooltip="" dataName="PAYMENTMETHOD_NAME" dataType="VARCHAR" dataLength="20" dataNullable="true" widgetType="TEXTBOX" widgetSize="" widgetLength="20" widgetIsMajor="true"></property>
</entity>
<entity name="SentMethod" dataName="SENTMETHOD" dataCount="SELECT COUNT(*) AS COUNT FROM &quot;${tablePrefix}SENTMETHOD&quot;" dataQuery="" type="SETTING" title="SentMethod" caption="Manage entity SentMethod" description="Manage entity SentMethod" tooltip="SentMethod" icon="/services/web/resources/unicons/file.svg" menuKey="sentmethod" menuLabel="SentMethod" menuIndex="100" layoutType="MANAGE" navigationPath="/Home" perspectiveName="SentMethod" perspectiveLabel="SentMethod" perspectiveIcon="/services/web/resources/unicons/archive.svg" perspectiveOrder="200" perspectiveRole="" generateReport="false" generateDefaultRoles="false">
<entity name="SentMethod" dataName="SENTMETHOD" dataCount="SELECT COUNT(*) AS COUNT FROM &quot;${tablePrefix}SENTMETHOD&quot;" dataQuery="" type="SETTING" title="SentMethod" caption="Manage entity SentMethod" description="Manage entity SentMethod" tooltip="SentMethod" icon="/services/web/resources/unicons/file.svg" menuKey="sentmethod" menuLabel="SentMethod" menuIndex="100" layoutType="MANAGE" navigationPath="/Home" perspectiveName="SentMethod" perspectiveLabel="SentMethod" perspectiveIcon="/services/web/resources/unicons/archive.svg" perspectiveOrder="200" perspectiveRole="" generateReport="false" generateDefaultRoles="true" roleRead="codbex-methods.SentMethod.SentMethodReadOnly" roleWrite="codbex-methods.SentMethod.SentMethodFullAccess">
<property name="Id" description="" tooltip="" dataName="SENTMETHOD_ID" dataType="INTEGER" dataNullable="true" dataPrimaryKey="true" dataAutoIncrement="true" widgetType="TEXTBOX" widgetSize="" widgetLength="20" widgetIsMajor="true"></property>
<property name="Name" description="" tooltip="" dataName="SENTMETHOD_NAME" dataType="VARCHAR" dataLength="20" dataNullable="true" widgetType="TEXTBOX" widgetSize="" widgetLength="20" widgetIsMajor="true"></property>
</entity>
Expand All @@ -15,5 +15,5 @@
</perspectives>
<navigations>
</navigations>
<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="2" style="entity" parent="1" vertex="1"><Entity name="PaymentMethod" dataName="PAYMENTMETHOD" dataCount="SELECT COUNT(*) AS COUNT FROM &quot;${tablePrefix}PAYMENTMETHOD&quot;" title="PaymentMethod" caption="Manage entity PaymentMethod" tooltip="PaymentMethod" menuLabel="PaymentMethod" type="Entity" menuKey="paymentmethod" disableGeneration="false" perspectiveName="PaymentMethod" entityType="SETTING" description="Manage entity PaymentMethod" as="value"><Array as="referenceProjections"/></Entity><mxGeometry x="20" y="80" width="200" height="80" as="geometry"><mxRectangle width="200" height="28" as="alternateBounds"/></mxGeometry></mxCell><mxCell id="3" parent="2" vertex="1" connectable="0"><Property name="Id" dataName="PAYMENTMETHOD_ID" dataType="INTEGER" dataLength="0" dataPrimaryKey="true" dataAutoIncrement="true" as="value"/><mxGeometry y="28" width="200" height="26" as="geometry"/></mxCell><mxCell id="4" parent="2" vertex="1" connectable="0"><Property name="Name" dataName="PAYMENTMETHOD_NAME" as="value"/><mxGeometry y="54" width="200" height="26" as="geometry"/></mxCell><mxCell id="5" style="entity" parent="1" vertex="1"><Entity name="SentMethod" dataName="SENTMETHOD" dataCount="SELECT COUNT(*) AS COUNT FROM &quot;${tablePrefix}SENTMETHOD&quot;" title="SentMethod" caption="Manage entity SentMethod" tooltip="SentMethod" menuLabel="SentMethod" type="Entity" menuKey="sentmethod" disableGeneration="false" perspectiveName="SentMethod" entityType="SETTING" description="Manage entity SentMethod" as="value"><Array as="referenceProjections"/></Entity><mxGeometry x="280" y="80" width="200" height="80" as="geometry"><mxRectangle width="200" height="28" as="alternateBounds"/></mxGeometry></mxCell><mxCell id="6" parent="5" vertex="1" connectable="0"><Property name="Id" dataName="SENTMETHOD_ID" dataType="INTEGER" dataLength="0" dataPrimaryKey="true" dataAutoIncrement="true" dataPrecision="NaN" dataScale="NaN" as="value"/><mxGeometry y="28" width="200" height="26" as="geometry"/></mxCell><mxCell id="7" parent="5" vertex="1" connectable="0"><Property name="Name" dataName="SENTMETHOD_NAME" dataPrecision="NaN" dataScale="NaN" as="value"/><mxGeometry y="54" width="200" height="26" as="geometry"/></mxCell></root></mxGraphModel>
<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="2" style="entity" parent="1" vertex="1"><Entity name="PaymentMethod" dataName="PAYMENTMETHOD" dataCount="SELECT COUNT(*) AS COUNT FROM &quot;${tablePrefix}PAYMENTMETHOD&quot;" title="PaymentMethod" caption="Manage entity PaymentMethod" tooltip="PaymentMethod" menuLabel="PaymentMethod" type="Entity" menuKey="paymentmethod" disableGeneration="false" perspectiveName="PaymentMethod" entityType="SETTING" description="Manage entity PaymentMethod" generateDefaultRoles="true" roleRead="codbex-methods.PaymentMethod.PaymentMethodReadOnly" roleWrite="codbex-methods.PaymentMethod.PaymentMethodFullAccess" as="value"><Array as="referenceProjections"/></Entity><mxGeometry x="20" y="20" width="200" height="80" as="geometry"><mxRectangle width="200" height="28" as="alternateBounds"/></mxGeometry></mxCell><mxCell id="3" parent="2" vertex="1" connectable="0"><Property name="Id" dataName="PAYMENTMETHOD_ID" dataType="INTEGER" dataLength="0" dataPrimaryKey="true" dataAutoIncrement="true" as="value"/><mxGeometry y="28" width="200" height="26" as="geometry"/></mxCell><mxCell id="4" parent="2" vertex="1" connectable="0"><Property name="Name" dataName="PAYMENTMETHOD_NAME" as="value"/><mxGeometry y="54" width="200" height="26" as="geometry"/></mxCell><mxCell id="5" style="entity" parent="1" vertex="1"><Entity name="SentMethod" dataName="SENTMETHOD" dataCount="SELECT COUNT(*) AS COUNT FROM &quot;${tablePrefix}SENTMETHOD&quot;" title="SentMethod" caption="Manage entity SentMethod" tooltip="SentMethod" menuLabel="SentMethod" type="Entity" menuKey="sentmethod" disableGeneration="false" perspectiveName="SentMethod" entityType="SETTING" description="Manage entity SentMethod" generateDefaultRoles="true" roleRead="codbex-methods.SentMethod.SentMethodReadOnly" roleWrite="codbex-methods.SentMethod.SentMethodFullAccess" as="value"><Array as="referenceProjections"/></Entity><mxGeometry x="270" y="20" width="200" height="80" as="geometry"><mxRectangle width="200" height="28" as="alternateBounds"/></mxGeometry></mxCell><mxCell id="6" parent="5" vertex="1" connectable="0"><Property name="Id" dataName="SENTMETHOD_ID" dataType="INTEGER" dataLength="0" dataPrimaryKey="true" dataAutoIncrement="true" dataPrecision="NaN" dataScale="NaN" as="value"/><mxGeometry y="28" width="200" height="26" as="geometry"/></mxCell><mxCell id="7" parent="5" vertex="1" connectable="0"><Property name="Name" dataName="SENTMETHOD_NAME" dataPrecision="NaN" dataScale="NaN" as="value"/><mxGeometry y="54" width="200" height="26" as="geometry"/></mxCell></root></mxGraphModel>
</model>
21 changes: 18 additions & 3 deletions codbex-methods/codbex-methods.gen
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@
"dataSource": "DefaultDB",
"fileName": "codbex-methods",
"genFolderName": "codbex-methods",
"roles": [],
"roles": [
{
"entityName": "PaymentMethod",
"roleRead": "codbex-methods.PaymentMethod.PaymentMethodReadOnly",
"roleWrite": "codbex-methods.PaymentMethod.PaymentMethodFullAccess"
},
{
"entityName": "SentMethod",
"roleRead": "codbex-methods.SentMethod.SentMethodReadOnly",
"roleWrite": "codbex-methods.SentMethod.SentMethodFullAccess"
}
],
"projectName": "codbex-methods",
"workspaceName": "workspace",
"filePath": "codbex-methods.model",
Expand Down Expand Up @@ -92,7 +103,7 @@
"dataName": "PAYMENTMETHOD",
"dataQuery": "",
"description": "Manage entity PaymentMethod",
"generateDefaultRoles": "false",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE",
Expand All @@ -106,6 +117,8 @@
"perspectiveName": "PaymentMethod",
"perspectiveOrder": "100",
"perspectiveRole": "",
"roleRead": "codbex-methods.PaymentMethod.PaymentMethodReadOnly",
"roleWrite": "codbex-methods.PaymentMethod.PaymentMethodFullAccess",
"title": "PaymentMethod",
"tooltip": "PaymentMethod",
"type": "SETTING",
Expand Down Expand Up @@ -173,7 +186,7 @@
"dataName": "SENTMETHOD",
"dataQuery": "",
"description": "Manage entity SentMethod",
"generateDefaultRoles": "false",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE",
Expand All @@ -187,6 +200,8 @@
"perspectiveName": "SentMethod",
"perspectiveOrder": "200",
"perspectiveRole": "",
"roleRead": "codbex-methods.SentMethod.SentMethodReadOnly",
"roleWrite": "codbex-methods.SentMethod.SentMethodFullAccess",
"title": "SentMethod",
"tooltip": "SentMethod",
"type": "SETTING",
Expand Down
8 changes: 6 additions & 2 deletions codbex-methods/codbex-methods.model
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"dataName": "PAYMENTMETHOD",
"dataQuery": "",
"description": "Manage entity PaymentMethod",
"generateDefaultRoles": "false",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE",
Expand All @@ -50,6 +50,8 @@
"perspectiveName": "PaymentMethod",
"perspectiveOrder": "100",
"perspectiveRole": "",
"roleRead": "codbex-methods.PaymentMethod.PaymentMethodReadOnly",
"roleWrite": "codbex-methods.PaymentMethod.PaymentMethodFullAccess",
"title": "PaymentMethod",
"tooltip": "PaymentMethod",
"type": "SETTING"
Expand Down Expand Up @@ -89,7 +91,7 @@
"dataName": "SENTMETHOD",
"dataQuery": "",
"description": "Manage entity SentMethod",
"generateDefaultRoles": "false",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE",
Expand All @@ -103,6 +105,8 @@
"perspectiveName": "SentMethod",
"perspectiveOrder": "200",
"perspectiveRole": "",
"roleRead": "codbex-methods.SentMethod.SentMethodReadOnly",
"roleWrite": "codbex-methods.SentMethod.SentMethodFullAccess",
"title": "SentMethod",
"tooltip": "SentMethod",
"type": "SETTING"
Expand Down
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 { PaymentMethodRepository, PaymentMethodEntityOptions } from "../../dao/PaymentMethod/PaymentMethodRepository";
import { user } from "sdk/security"
import { ForbiddenError } from "../utils/ForbiddenError";
import { ValidationError } from "../utils/ValidationError";
import { HttpUtils } from "../utils/HttpUtils";

Expand All @@ -14,6 +16,7 @@ class PaymentMethodService {
@Get("/")
public getAll(_: any, ctx: any) {
try {
this.checkPermissions("read");
const options: PaymentMethodEntityOptions = {
$limit: ctx.queryParameters["$limit"] ? parseInt(ctx.queryParameters["$limit"]) : undefined,
$offset: ctx.queryParameters["$offset"] ? parseInt(ctx.queryParameters["$offset"]) : undefined
Expand All @@ -28,6 +31,7 @@ class PaymentMethodService {
@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-methods/gen/codbex-methods/api/PaymentMethod/PaymentMethodService.ts/" + entity.Id);
Expand All @@ -41,6 +45,7 @@ class PaymentMethodService {
@Get("/count")
public count() {
try {
this.checkPermissions("read");
return this.repository.count();
} catch (error: any) {
this.handleError(error);
Expand All @@ -50,6 +55,7 @@ class PaymentMethodService {
@Post("/count")
public countWithFilter(filter: any) {
try {
this.checkPermissions("read");
return this.repository.count(filter);
} catch (error: any) {
this.handleError(error);
Expand All @@ -59,6 +65,7 @@ class PaymentMethodService {
@Post("/search")
public search(filter: any) {
try {
this.checkPermissions("read");
return this.repository.findAll(filter);
} catch (error: any) {
this.handleError(error);
Expand All @@ -68,6 +75,7 @@ class PaymentMethodService {
@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 @@ -83,6 +91,7 @@ class PaymentMethodService {
@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 @@ -95,6 +104,7 @@ class PaymentMethodService {
@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 @@ -118,6 +128,15 @@ class PaymentMethodService {
}
}

private checkPermissions(operationType: string) {
if (operationType === "read" && !(user.isInRole("codbex-methods.PaymentMethod.PaymentMethodReadOnly") || user.isInRole("codbex-methods.PaymentMethod.PaymentMethodFullAccess"))) {
throw new ForbiddenError();
}
if (operationType === "write" && !user.isInRole("codbex-methods.PaymentMethod.PaymentMethodFullAccess")) {
throw new ForbiddenError();
}
}

private validateEntity(entity: any): void {
if (entity.Name?.length > 20) {
throw new ValidationError(`The 'Name' exceeds the maximum length of [20] characters`);
Expand Down
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 { SentMethodRepository, SentMethodEntityOptions } from "../../dao/SentMethod/SentMethodRepository";
import { user } from "sdk/security"
import { ForbiddenError } from "../utils/ForbiddenError";
import { ValidationError } from "../utils/ValidationError";
import { HttpUtils } from "../utils/HttpUtils";

Expand All @@ -14,6 +16,7 @@ class SentMethodService {
@Get("/")
public getAll(_: any, ctx: any) {
try {
this.checkPermissions("read");
const options: SentMethodEntityOptions = {
$limit: ctx.queryParameters["$limit"] ? parseInt(ctx.queryParameters["$limit"]) : undefined,
$offset: ctx.queryParameters["$offset"] ? parseInt(ctx.queryParameters["$offset"]) : undefined
Expand All @@ -28,6 +31,7 @@ class SentMethodService {
@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-methods/gen/codbex-methods/api/SentMethod/SentMethodService.ts/" + entity.Id);
Expand All @@ -41,6 +45,7 @@ class SentMethodService {
@Get("/count")
public count() {
try {
this.checkPermissions("read");
return this.repository.count();
} catch (error: any) {
this.handleError(error);
Expand All @@ -50,6 +55,7 @@ class SentMethodService {
@Post("/count")
public countWithFilter(filter: any) {
try {
this.checkPermissions("read");
return this.repository.count(filter);
} catch (error: any) {
this.handleError(error);
Expand All @@ -59,6 +65,7 @@ class SentMethodService {
@Post("/search")
public search(filter: any) {
try {
this.checkPermissions("read");
return this.repository.findAll(filter);
} catch (error: any) {
this.handleError(error);
Expand All @@ -68,6 +75,7 @@ class SentMethodService {
@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 @@ -83,6 +91,7 @@ class SentMethodService {
@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 @@ -95,6 +104,7 @@ class SentMethodService {
@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 @@ -118,6 +128,15 @@ class SentMethodService {
}
}

private checkPermissions(operationType: string) {
if (operationType === "read" && !(user.isInRole("codbex-methods.SentMethod.SentMethodReadOnly") || user.isInRole("codbex-methods.SentMethod.SentMethodFullAccess"))) {
throw new ForbiddenError();
}
if (operationType === "write" && !user.isInRole("codbex-methods.SentMethod.SentMethodFullAccess")) {
throw new ForbiddenError();
}
}

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