From 90f934671bfeeadb17646f09fa2591cade4b573c Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Wed, 12 Apr 2023 19:03:09 +0300 Subject: [PATCH] 1.2.6 - Removed specific user groups and roles. Records must be dynamic. --- README.md | 3 +- package-lock.json | 4 +-- package.json | 2 +- src/constants/userRoles.ts | 11 ------- src/hooks/useTuitioUserInfo.ts | 41 +++----------------------- tests/hooks/useTuitioUserInfo.test.tsx | 5 +--- 6 files changed, 10 insertions(+), 56 deletions(-) delete mode 100644 src/constants/userRoles.ts diff --git a/README.md b/README.md index 25fa6dc..6b53c24 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,5 @@ All tests in the package can be executed by running: `npm test`. 1.2.2 - Upgraded @flare/tuitio-client and @flare/js-utils packages. 1.2.3 - User roles were handled in useTuitioUserInfo hook. 1.2.4 - Upgraded @flare/tuitio-client. -1.2.5 - Upgraded @flare/tuitio-client. +1.2.5 - Upgraded @flare/tuitio-client. +1.2.6 - Removed specific user groups and roles. Records must be dynamic. diff --git a/package-lock.json b/package-lock.json index c25baba..7ce1626 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@flare/tuitio-client-react", - "version": "1.2.5", + "version": "1.2.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@flare/tuitio-client-react", - "version": "1.2.5", + "version": "1.2.6", "license": "MIT", "dependencies": { "@flare/js-utils": "^1.1.0", diff --git a/package.json b/package.json index bdd3915..28cd86d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@flare/tuitio-client-react", - "version": "1.2.5", + "version": "1.2.6", "description": "Tuitio client react is an npm package written in typescript that facilitates the integration of a react application with Tuitio.", "main": "./dist/cjs/index.js", "module": "./dist/esm/index.js", diff --git a/src/constants/userRoles.ts b/src/constants/userRoles.ts deleted file mode 100644 index af5f49a..0000000 --- a/src/constants/userRoles.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2023 Tudor Stanciu - -export const userRoles = { - SYS_ADMIN: "SYSTEM_ADMINISTRATOR", - DEVELOPER: "FULLSTACK_DEVELOPER", - POWER_USER: "POWER_USER", - REGULAR_USER: "REGULAR_USER", - VIEWER: "READONLY_USER", - GUEST: "ANONYMOUS_USER", - DEMO: "DEMO_USER" -}; diff --git a/src/hooks/useTuitioUserInfo.ts b/src/hooks/useTuitioUserInfo.ts index 060194b..6d37fa5 100644 --- a/src/hooks/useTuitioUserInfo.ts +++ b/src/hooks/useTuitioUserInfo.ts @@ -1,46 +1,14 @@ // Copyright (c) 2023 Tudor Stanciu -import { useContext, useCallback, useEffect, useMemo } from "react"; +import { useContext, useCallback, useEffect } from "react"; import { TuitioClient } from "@flare/tuitio-client"; -import type { TuitioUserInfo, UserRole } from "@flare/tuitio-client"; +import type { TuitioUserInfo } from "@flare/tuitio-client"; import { TuitioContext, TuitioDispatchContext } from "../contexts"; -import { userRoles } from "../constants/userRoles"; -type UserFlags = { - isSysAdmin: boolean; - isDeveloper: boolean; - isPowerUser: boolean; - isRegularUser: boolean; - isViewer: boolean; - isGuest: boolean; - isDemoGuest: boolean; -}; - -const defaultUserFlags: UserFlags = { - isSysAdmin: false, - isDeveloper: false, - isPowerUser: false, - isRegularUser: false, - isViewer: false, - isGuest: false, - isDemoGuest: false -}; - -export type TuitioUserInfoHookResult = UserFlags & { +export type TuitioUserInfoHookResult = { userInfo?: TuitioUserInfo; }; -const getFlags = (roles: UserRole[]): UserFlags => { - const isSysAdmin = roles.some(role => role.code === userRoles.SYS_ADMIN); - const isDeveloper = roles.some(role => role.code === userRoles.DEVELOPER); - const isPowerUser = roles.some(role => role.code === userRoles.POWER_USER); - const isRegularUser = roles.some(role => role.code === userRoles.REGULAR_USER); - const isViewer = roles.some(role => role.code === userRoles.VIEWER); - const isGuest = roles.some(role => role.code === userRoles.GUEST); - const isDemoGuest = roles.some(role => role.code === userRoles.DEMO); - return { isSysAdmin, isDeveloper, isPowerUser, isRegularUser, isViewer, isGuest, isDemoGuest }; -}; - const useTuitioUserInfo = (): TuitioUserInfoHookResult => { const state = useContext(TuitioContext); const dispatchActions = useContext(TuitioDispatchContext); @@ -58,9 +26,8 @@ const useTuitioUserInfo = (): TuitioUserInfoHookResult => { }, [getUserInfo, state.userInfo]); const userInfo = state.userInfo; - const flags = useMemo(() => (userInfo ? getFlags(userInfo.userRoles) : defaultUserFlags), [userInfo]); - return { userInfo, ...flags }; + return { userInfo }; }; export { useTuitioUserInfo }; diff --git a/tests/hooks/useTuitioUserInfo.test.tsx b/tests/hooks/useTuitioUserInfo.test.tsx index 15d073d..d606c96 100644 --- a/tests/hooks/useTuitioUserInfo.test.tsx +++ b/tests/hooks/useTuitioUserInfo.test.tsx @@ -75,14 +75,11 @@ describe("useTuitioUserInfo: dispatchActions", () => { expect(onUserInfoLoadedSpy).toHaveBeenCalled(); expect(onUserInfoLoadedSpy).toHaveBeenCalledWith(userInfoMock); - const { userInfo, isSysAdmin, isDeveloper, isGuest } = result.current; + const { userInfo } = result.current; expect(userInfo).toBeDefined(); expect(userInfo?.userId).toBe(1); expect(userInfo?.userName).toBe("tuitio.test"); expect(userInfo?.userRoles).toHaveLength(2); expect(userInfo?.userGroups).toHaveLength(1); - expect(isSysAdmin).toBe(true); - expect(isDeveloper).toBe(true); - expect(isGuest).toBe(false); }); });