From f3e4bdc220ba22df18abcf04966763e36d03fdae Mon Sep 17 00:00:00 2001
From: Alberto Defendi <1369-ahl-berto@users.noreply.gitlab.inf.unibz.it>
Date: Mon, 21 Jun 2021 08:42:02 +0200
Subject: [PATCH] Define roles in this folder.

---
 src/roles/All.tsx      | 12 ++++++++++++
 src/roles/Operator.tsx |  7 +++++++
 src/roles/Senior.tsx   |  7 +++++++
 src/roles/userRoles.ts | 12 ++++++++++++
 4 files changed, 38 insertions(+)
 create mode 100644 src/roles/All.tsx
 create mode 100644 src/roles/Operator.tsx
 create mode 100644 src/roles/Senior.tsx
 create mode 100644 src/roles/userRoles.ts

diff --git a/src/roles/All.tsx b/src/roles/All.tsx
new file mode 100644
index 0000000..2e94b3d
--- /dev/null
+++ b/src/roles/All.tsx
@@ -0,0 +1,12 @@
+import { withAuthorization } from 'components/Authorization/Authorization';
+import { Roles } from 'roles/userRoles';
+
+/**
+ * Wrapper for pages that can be accessed by all roles.
+ */
+export const All = withAuthorization([
+  Roles.admin,
+  Roles.operator,
+  Roles.senior,
+  Roles.driver,
+]);
diff --git a/src/roles/Operator.tsx b/src/roles/Operator.tsx
new file mode 100644
index 0000000..c5ba47a
--- /dev/null
+++ b/src/roles/Operator.tsx
@@ -0,0 +1,7 @@
+import { withAuthorization } from 'components/Authorization/Authorization';
+import { Roles } from 'roles/userRoles';
+
+/**
+ * Wrapper for pages that can be accessed by operators.
+ */
+export const Operator = withAuthorization([Roles.operator]);
diff --git a/src/roles/Senior.tsx b/src/roles/Senior.tsx
new file mode 100644
index 0000000..8de0533
--- /dev/null
+++ b/src/roles/Senior.tsx
@@ -0,0 +1,7 @@
+import { withAuthorization } from 'components/Authorization/Authorization';
+import { Roles } from 'roles/userRoles';
+
+/**
+ * Wrapper for pages that can be accessed by seniors.
+ */
+export const Senior = withAuthorization([Roles.senior]);
diff --git a/src/roles/userRoles.ts b/src/roles/userRoles.ts
new file mode 100644
index 0000000..9a6b847
--- /dev/null
+++ b/src/roles/userRoles.ts
@@ -0,0 +1,12 @@
+/**
+ * User roles of the application.
+ */
+export enum Roles {
+  /** Website visitor, is not logged. Can access to NonAuthRoutes */
+  visitor = '',
+  /** Can access to routes wrapped by withAuthorization. */
+  senior = 'senior',
+  admin = 'admin',
+  operator = 'operator',
+  driver = 'driver',
+}
-- 
GitLab