aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/framework/src/services/restService.ts
diff options
context:
space:
mode:
authorMichael DÜrre <michael.duerre@highstreet-technologies.com>2021-04-08 07:27:18 +0200
committerMichael DÜrre <michael.duerre@highstreet-technologies.com>2021-04-08 07:27:28 +0200
commit21e4a946cd24b8a03ea577352f0271ebf7669ffa (patch)
tree4227d8566770b75c2c25b67c764038288cacfe3d /sdnr/wt/odlux/framework/src/services/restService.ts
parenta252be83694ae33260d99d5371ed48c1558aa2e8 (diff)
update odlux for notification change
update due new notification protocol Issue-ID: CCSDK-3253 Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com> Change-Id: Iad65459fdc18603cd1ddbd97bb2211308744bd8b
Diffstat (limited to 'sdnr/wt/odlux/framework/src/services/restService.ts')
-rw-r--r--sdnr/wt/odlux/framework/src/services/restService.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/sdnr/wt/odlux/framework/src/services/restService.ts b/sdnr/wt/odlux/framework/src/services/restService.ts
index f05c7b89f..c7b122449 100644
--- a/sdnr/wt/odlux/framework/src/services/restService.ts
+++ b/sdnr/wt/odlux/framework/src/services/restService.ts
@@ -15,6 +15,8 @@
* the License.
* ============LICENSE_END==========================================================================
*/
+
+
import { ApplicationStore } from "../store/applicationStore";
import { ReplaceAction } from "../actions/navigationActions";
@@ -30,6 +32,46 @@ export const formEncode = (params: { [key: string]: string | number }) => Object
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key].toString());
}).join('&');
+const wildcardToRegexp = (pattern: string) => {
+ return new RegExp('^' + pattern.split(/\*\*/).map((p) => p.split(/\*+/).map((i) => i.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')).join('^[/]')).join('.*') + '$');
+};
+
+export const getAccessPolicyByUrl = (url: string) => {
+ const result = {
+ GET : false,
+ POST: false,
+ PUT: false,
+ PATCH: false,
+ DELETE: false,
+ };
+
+ if (!applicationStore) return result;
+
+ const { state: { framework: { applicationState: { enablePolicy }, authenticationState: { policies }}} } = applicationStore!;
+
+ result.GET = true;
+ result.POST = true;
+ result.PUT = true;
+ result.PATCH = true;
+ result.DELETE = true;
+
+ if (!enablePolicy || !policies || policies.length === 0) return result;
+
+ policies.forEach(p => {
+ const re = wildcardToRegexp(p.path);
+ if (re.test(url)) {
+ result.GET = p.methods.get != null ? p.methods.get : result.GET ;
+ result.POST = p.methods.post != null ? p.methods.post : result.POST ;
+ result.PUT = p.methods.put != null ? p.methods.put : result.PUT ;
+ result.PATCH = p.methods.patch != null ? p.methods.patch : result.PATCH ;
+ result.DELETE = p.methods.delete != null ? p.methods.delete : result.DELETE ;
+ }
+ });
+
+ return result;
+
+}
+
/** Sends a rest request to the given path.
* @returns The data, or null it there was any error
*/