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
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ Organizations Management Module

### Model

<img width="682" alt="Screenshot 2024-09-10 at 18 40 05" src="https://github.com/user-attachments/assets/6eb5c9a9-2a8d-4c6b-bd74-47d50f3e1c75">
![model](images/organizations-model.png)

### Application

#### Launchpad
<img width="1418" alt="Screenshot 2024-09-09 at 9 28 22" src="https://github.com/user-attachments/assets/3d5e61b2-7c56-4ede-b06a-997b7212a724">

![launchpad](images/organizations-launchpad.png)

#### Management

<img width="1407" alt="Screenshot 2024-09-09 at 9 31 49" src="https://github.com/user-attachments/assets/6b391628-bda1-467e-a60b-2cc44b62aa50">

![management](images/organizations-management.png)

![management](images/teams-management.png)


12 changes: 6 additions & 6 deletions codbex-organizations/codbex-organizations.edm

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions codbex-organizations/codbex-organizations.gen
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@
"role": ""
}
},
"roles": [
{
"entityName": "Organization",
"roleRead": "codbex-organizations.Organizations.OrganizationReadOnly",
"roleWrite": "codbex-organizations.Organizations.OrganizationFullAccess"
},
{
"entityName": "Department",
"roleRead": "codbex-organizations.Organizations.DepartmentReadOnly",
"roleWrite": "codbex-organizations.Organizations.DepartmentFullAccess"
},
{
"entityName": "Team",
"roleRead": "codbex-organizations.Teams.TeamReadOnly",
"roleWrite": "codbex-organizations.Teams.TeamFullAccess"
}
],
"models": [
{
"properties": [
Expand Down Expand Up @@ -213,6 +230,7 @@
"dataName": "ORGANIZATION",
"dataQuery": "",
"description": "Manage entity Organization",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE_MASTER",
Expand All @@ -226,6 +244,8 @@
"perspectiveName": "Organizations",
"perspectiveOrder": "100",
"perspectiveRole": "",
"roleRead": "codbex-organizations.Organizations.OrganizationReadOnly",
"roleWrite": "codbex-organizations.Organizations.OrganizationFullAccess",
"title": "Organization",
"tooltip": "Organization",
"type": "PRIMARY",
Expand Down Expand Up @@ -416,6 +436,7 @@
"dataName": "DEPARTMENT",
"dataQuery": "",
"description": "Manage entity Department",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE_DETAILS",
Expand All @@ -429,6 +450,8 @@
"perspectiveName": "Organizations",
"perspectiveOrder": "100",
"perspectiveRole": "",
"roleRead": "codbex-organizations.Organizations.DepartmentReadOnly",
"roleWrite": "codbex-organizations.Organizations.DepartmentFullAccess",
"title": "Department",
"tooltip": "Department",
"type": "DEPENDENT",
Expand Down Expand Up @@ -737,6 +760,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 @@ -911,6 +935,7 @@
"dataName": "TEAM",
"dataQuery": "",
"description": "Manage entity Team",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE_MASTER",
Expand All @@ -924,6 +949,8 @@
"perspectiveName": "Teams",
"perspectiveOrder": "106",
"perspectiveRole": "",
"roleRead": "codbex-organizations.Teams.TeamReadOnly",
"roleWrite": "codbex-organizations.Teams.TeamFullAccess",
"title": "Team",
"tooltip": "Team",
"type": "PRIMARY",
Expand Down Expand Up @@ -1361,6 +1388,7 @@
"dataName": "EMPLOYEE",
"dataQuery": "",
"description": "Manage entity Employee",
"generateDefaultRoles": "false",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE",
Expand Down
11 changes: 11 additions & 0 deletions codbex-organizations/codbex-organizations.model
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"dataName": "ORGANIZATION",
"dataQuery": "",
"description": "Manage entity Organization",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE_MASTER",
Expand All @@ -82,6 +83,8 @@
"perspectiveName": "Organizations",
"perspectiveOrder": "100",
"perspectiveRole": "",
"roleRead": "codbex-organizations.Organizations.OrganizationReadOnly",
"roleWrite": "codbex-organizations.Organizations.OrganizationFullAccess",
"title": "Organization",
"tooltip": "Organization",
"type": "PRIMARY"
Expand Down Expand Up @@ -143,6 +146,7 @@
"dataName": "DEPARTMENT",
"dataQuery": "",
"description": "Manage entity Department",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE_DETAILS",
Expand All @@ -156,6 +160,8 @@
"perspectiveName": "Organizations",
"perspectiveOrder": "100",
"perspectiveRole": "",
"roleRead": "codbex-organizations.Organizations.DepartmentReadOnly",
"roleWrite": "codbex-organizations.Organizations.DepartmentFullAccess",
"title": "Department",
"tooltip": "Department",
"type": "DEPENDENT"
Expand Down Expand Up @@ -324,6 +330,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 @@ -438,6 +445,7 @@
"dataName": "TEAM",
"dataQuery": "",
"description": "Manage entity Team",
"generateDefaultRoles": "true",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE_MASTER",
Expand All @@ -451,6 +459,8 @@
"perspectiveName": "Teams",
"perspectiveOrder": "106",
"perspectiveRole": "",
"roleRead": "codbex-organizations.Teams.TeamReadOnly",
"roleWrite": "codbex-organizations.Teams.TeamFullAccess",
"title": "Team",
"tooltip": "Team",
"type": "PRIMARY"
Expand Down Expand Up @@ -634,6 +644,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,6 +1,8 @@
import { Controller, Get, Post, Put, Delete, response } from "sdk/http"
import { Extensions } from "sdk/extensions"
import { DepartmentRepository, DepartmentEntityOptions } from "../../dao/Organizations/DepartmentRepository";
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 DepartmentService {
@Get("/")
public getAll(_: any, ctx: any) {
try {
this.checkPermissions("read");
const options: DepartmentEntityOptions = {
$limit: ctx.queryParameters["$limit"] ? parseInt(ctx.queryParameters["$limit"]) : undefined,
$offset: ctx.queryParameters["$offset"] ? parseInt(ctx.queryParameters["$offset"]) : undefined
Expand All @@ -39,6 +42,7 @@ class DepartmentService {
@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-organizations/gen/codbex-organizations/api/Organizations/DepartmentService.ts/" + entity.Id);
Expand All @@ -52,6 +56,7 @@ class DepartmentService {
@Get("/count")
public count() {
try {
this.checkPermissions("read");
return this.repository.count();
} catch (error: any) {
this.handleError(error);
Expand All @@ -61,6 +66,7 @@ class DepartmentService {
@Post("/count")
public countWithFilter(filter: any) {
try {
this.checkPermissions("read");
return this.repository.count(filter);
} catch (error: any) {
this.handleError(error);
Expand All @@ -70,6 +76,7 @@ class DepartmentService {
@Post("/search")
public search(filter: any) {
try {
this.checkPermissions("read");
return this.repository.findAll(filter);
} catch (error: any) {
this.handleError(error);
Expand All @@ -79,6 +86,7 @@ class DepartmentService {
@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 @@ -94,6 +102,7 @@ class DepartmentService {
@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 @@ -106,6 +115,7 @@ class DepartmentService {
@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 @@ -129,6 +139,15 @@ class DepartmentService {
}
}

private checkPermissions(operationType: string) {
if (operationType === "read" && !(user.isInRole("codbex-organizations.Organizations.DepartmentReadOnly") || user.isInRole("codbex-organizations.Organizations.DepartmentFullAccess"))) {
throw new ForbiddenError();
}
if (operationType === "write" && !user.isInRole("codbex-organizations.Organizations.DepartmentFullAccess")) {
throw new ForbiddenError();
}
}

private validateEntity(entity: any): void {
if (entity.Name === null || entity.Name === undefined) {
throw new ValidationError(`The 'Name' property is required, provide a valid value`);
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 { OrganizationRepository, OrganizationEntityOptions } from "../../dao/Organizations/OrganizationRepository";
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 OrganizationService {
@Get("/")
public getAll(_: any, ctx: any) {
try {
this.checkPermissions("read");
const options: OrganizationEntityOptions = {
$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 OrganizationService {
@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-organizations/gen/codbex-organizations/api/Organizations/OrganizationService.ts/" + entity.Id);
Expand All @@ -41,6 +45,7 @@ class OrganizationService {
@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 OrganizationService {
@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 OrganizationService {
@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 OrganizationService {
@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 OrganizationService {
@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 OrganizationService {
@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 OrganizationService {
}
}

private checkPermissions(operationType: string) {
if (operationType === "read" && !(user.isInRole("codbex-organizations.Organizations.OrganizationReadOnly") || user.isInRole("codbex-organizations.Organizations.OrganizationFullAccess"))) {
throw new ForbiddenError();
}
if (operationType === "write" && !user.isInRole("codbex-organizations.Organizations.OrganizationFullAccess")) {
throw new ForbiddenError();
}
}

private validateEntity(entity: any): void {
if (entity.Name === null || entity.Name === undefined) {
throw new ValidationError(`The 'Name' property is required, provide a valid value`);
Expand Down
Loading