Compare commits

...

3 Commits

Author SHA1 Message Date
Lakhan Samani
78a673e4ad fix: fix parallel access of env vars 2022-06-08 09:50:30 +05:30
Lakhan Samani
e0d8644264 fix: role validation while signup 2022-06-07 08:00:30 +05:30
Lakhan Samani
d8c662eaad fix: dashboard roles 2022-06-07 07:30:01 +05:30
6 changed files with 74 additions and 83 deletions

View File

@@ -1,67 +1,68 @@
import React from "react"; import React from 'react';
import { Flex, Stack, Center, Text, useMediaQuery } from "@chakra-ui/react"; import { Flex, Stack, Center, Text, useMediaQuery } from '@chakra-ui/react';
import { ArrayInputType } from "../../constants"; import { ArrayInputType } from '../../constants';
import InputField from "../InputField"; import InputField from '../InputField';
const Roles = ({ variables, setVariables }: any) => { const Roles = ({ variables, setVariables }: any) => {
const [isNotSmallerScreen] = useMediaQuery("(min-width:600px)"); const [isNotSmallerScreen] = useMediaQuery('(min-width:600px)');
return (
<div> return (
{" "} <div>
<Text fontSize="md" paddingTop="2%" fontWeight="bold" mb={5}> {' '}
Roles <Text fontSize="md" paddingTop="2%" fontWeight="bold" mb={5}>
</Text> Roles
<Stack spacing={6} padding="2% 0%"> </Text>
<Flex direction={isNotSmallerScreen ? "row" : "column"}> <Stack spacing={6} padding="2% 0%">
<Flex w="30%" justifyContent="start" alignItems="center"> <Flex direction={isNotSmallerScreen ? 'row' : 'column'}>
<Text fontSize="sm">Roles:</Text> <Flex w="30%" justifyContent="start" alignItems="center">
</Flex> <Text fontSize="sm">Roles:</Text>
<Center </Flex>
w={isNotSmallerScreen ? "70%" : "100%"} <Center
mt={isNotSmallerScreen ? "0" : "2"} w={isNotSmallerScreen ? '70%' : '100%'}
overflow="hidden" mt={isNotSmallerScreen ? '0' : '2'}
> overflow="hidden"
<InputField >
borderRadius={7} <InputField
variables={variables} borderRadius={7}
setVariables={setVariables} variables={variables}
inputType={ArrayInputType.ROLES} setVariables={setVariables}
/> inputType={ArrayInputType.ROLES}
</Center> />
</Flex> </Center>
<Flex direction={isNotSmallerScreen ? "row" : "column"}> </Flex>
<Flex w="30%" justifyContent="start" alignItems="center"> <Flex direction={isNotSmallerScreen ? 'row' : 'column'}>
<Text fontSize="sm">Default Roles:</Text> <Flex w="30%" justifyContent="start" alignItems="center">
</Flex> <Text fontSize="sm">Default Roles:</Text>
<Center </Flex>
w={isNotSmallerScreen ? "70%" : "100%"} <Center
mt={isNotSmallerScreen ? "0" : "2"} w={isNotSmallerScreen ? '70%' : '100%'}
> mt={isNotSmallerScreen ? '0' : '2'}
<InputField >
variables={variables} <InputField
setVariables={setVariables} variables={variables}
inputType={ArrayInputType.DEFAULT_ROLES} setVariables={setVariables}
/> inputType={ArrayInputType.DEFAULT_ROLES}
</Center> />
</Flex> </Center>
<Flex direction={isNotSmallerScreen ? "row" : "column"}> </Flex>
<Flex w="30%" justifyContent="start" alignItems="center"> <Flex direction={isNotSmallerScreen ? 'row' : 'column'}>
<Text fontSize="sm">Protected Roles:</Text> <Flex w="30%" justifyContent="start" alignItems="center">
</Flex> <Text fontSize="sm">Protected Roles:</Text>
<Center </Flex>
w={isNotSmallerScreen ? "70%" : "100%"} <Center
mt={isNotSmallerScreen ? "0" : "2"} w={isNotSmallerScreen ? '70%' : '100%'}
> mt={isNotSmallerScreen ? '0' : '2'}
<InputField >
variables={variables} <InputField
setVariables={setVariables} variables={variables}
inputType={ArrayInputType.PROTECTED_ROLES} setVariables={setVariables}
/> inputType={ArrayInputType.PROTECTED_ROLES}
</Center> />
</Flex> </Center>
</Stack> </Flex>
</div> </Stack>
); </div>
);
}; };
export default Roles; export default Roles;

View File

@@ -30,6 +30,7 @@ export const EnvVariablesQuery = `
LINKEDIN_CLIENT_SECRET, LINKEDIN_CLIENT_SECRET,
DEFAULT_ROLES, DEFAULT_ROLES,
PROTECTED_ROLES, PROTECTED_ROLES,
ROLES,
JWT_TYPE, JWT_TYPE,
JWT_SECRET, JWT_SECRET,
JWT_ROLE_CLAIM, JWT_ROLE_CLAIM,

View File

@@ -26,20 +26,11 @@ func (e *EnvStore) UpdateStore(store map[string]interface{}) {
// GetStore returns the env store // GetStore returns the env store
func (e *EnvStore) GetStore() map[string]interface{} { func (e *EnvStore) GetStore() map[string]interface{} {
if os.Getenv("ENV") != "test" {
e.mutex.Lock()
defer e.mutex.Unlock()
}
return e.store return e.store
} }
// Get returns the value of the key in evn store // Get returns the value of the key in evn store
func (e *EnvStore) Get(key string) interface{} { func (e *EnvStore) Get(key string) interface{} {
if os.Getenv("ENV") != "test" {
e.mutex.Lock()
defer e.mutex.Unlock()
}
return e.store[key] return e.store[key]
} }

View File

@@ -19,10 +19,6 @@ func (c *provider) ClearStore() error {
// GetUserSessions returns all the user session token from the in-memory store. // GetUserSessions returns all the user session token from the in-memory store.
func (c *provider) GetUserSessions(userId string) map[string]string { func (c *provider) GetUserSessions(userId string) map[string]string {
if os.Getenv("ENV") != "test" {
c.mutex.Lock()
defer c.mutex.Unlock()
}
res := map[string]string{} res := map[string]string{}
for k, v := range c.stateStore { for k, v := range c.stateStore {
split := strings.Split(v, "@") split := strings.Split(v, "@")
@@ -61,11 +57,6 @@ func (c *provider) SetState(key, state string) error {
// GetState gets the state from the in-memory store. // GetState gets the state from the in-memory store.
func (c *provider) GetState(key string) (string, error) { func (c *provider) GetState(key string) (string, error) {
if os.Getenv("ENV") != "test" {
c.mutex.Lock()
defer c.mutex.Unlock()
}
state := "" state := ""
if stateVal, ok := c.stateStore[key]; ok { if stateVal, ok := c.stateStore[key]; ok {
state = stateVal state = stateVal

View File

@@ -147,7 +147,14 @@ func EnvResolver(ctx context.Context) (*model.Env, error) {
res.AllowedOrigins = strings.Split(store[constants.EnvKeyAllowedOrigins].(string), ",") res.AllowedOrigins = strings.Split(store[constants.EnvKeyAllowedOrigins].(string), ",")
res.Roles = strings.Split(store[constants.EnvKeyRoles].(string), ",") res.Roles = strings.Split(store[constants.EnvKeyRoles].(string), ",")
res.DefaultRoles = strings.Split(store[constants.EnvKeyDefaultRoles].(string), ",") res.DefaultRoles = strings.Split(store[constants.EnvKeyDefaultRoles].(string), ",")
res.ProtectedRoles = strings.Split(store[constants.EnvKeyProtectedRoles].(string), ",") // since protected role is optional default split gives array with empty string
protectedRoles := strings.Split(store[constants.EnvKeyProtectedRoles].(string), ",")
res.ProtectedRoles = []string{}
for _, role := range protectedRoles {
if strings.Trim(role, " ") != "" {
res.ProtectedRoles = append(res.ProtectedRoles, strings.Trim(role, " "))
}
}
// bool vars // bool vars
res.DisableEmailVerification = store[constants.EnvKeyDisableEmailVerification].(bool) res.DisableEmailVerification = store[constants.EnvKeyDisableEmailVerification].(bool)

View File

@@ -100,7 +100,7 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
} else { } else {
roles = strings.Split(rolesString, ",") roles = strings.Split(rolesString, ",")
} }
if !validators.IsValidRoles(roles, params.Roles) { if !validators.IsValidRoles(params.Roles, roles) {
log.Debug("Invalid roles: ", params.Roles) log.Debug("Invalid roles: ", params.Roles)
return res, fmt.Errorf(`invalid roles`) return res, fmt.Errorf(`invalid roles`)
} else { } else {