fix: slice envs
This commit is contained in:
@@ -87,10 +87,15 @@ func InviteMembersResolver(ctx context.Context, params model.InviteMemberInput)
|
||||
// invite new emails
|
||||
for _, email := range newEmails {
|
||||
|
||||
defaultRoles, err := memorystore.Provider.GetSliceStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
||||
defaultRolesString, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
||||
defaultRoles := []string{}
|
||||
if err != nil {
|
||||
log.Debug("Error getting default roles: ", err)
|
||||
defaultRolesString = ""
|
||||
} else {
|
||||
defaultRoles = strings.Split(defaultRolesString, ",")
|
||||
}
|
||||
|
||||
user := models.User{
|
||||
Email: email,
|
||||
Roles: strings.Join(defaultRoles, ","),
|
||||
|
@@ -73,10 +73,15 @@ func LoginResolver(ctx context.Context, params model.LoginInput) (*model.AuthRes
|
||||
return res, fmt.Errorf(`invalid password`)
|
||||
}
|
||||
|
||||
roles, err := memorystore.Provider.GetSliceStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
||||
defaultRolesString, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
||||
roles := []string{}
|
||||
if err != nil {
|
||||
log.Debug("Error getting default roles: ", err)
|
||||
defaultRolesString = ""
|
||||
} else {
|
||||
roles = strings.Split(defaultRolesString, ",")
|
||||
}
|
||||
|
||||
currentRoles := strings.Split(user.Roles, ",")
|
||||
if len(params.Roles) > 0 {
|
||||
if !validators.IsValidRoles(params.Roles, currentRoles) {
|
||||
|
@@ -74,10 +74,13 @@ func MagicLinkLoginResolver(ctx context.Context, params model.MagicLinkLoginInpu
|
||||
// define roles for new user
|
||||
if len(params.Roles) > 0 {
|
||||
// check if roles exists
|
||||
roles, err := memorystore.Provider.GetSliceStoreEnvVariable(constants.EnvKeyRoles)
|
||||
rolesString, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyRoles)
|
||||
roles := []string{}
|
||||
if err != nil {
|
||||
log.Debug("Error getting roles: ", err)
|
||||
return res, err
|
||||
} else {
|
||||
roles = strings.Split(rolesString, ",")
|
||||
}
|
||||
if !validators.IsValidRoles(params.Roles, roles) {
|
||||
log.Debug("Invalid roles: ", params.Roles)
|
||||
@@ -86,12 +89,13 @@ func MagicLinkLoginResolver(ctx context.Context, params model.MagicLinkLoginInpu
|
||||
inputRoles = params.Roles
|
||||
}
|
||||
} else {
|
||||
inputRoles, err = memorystore.Provider.GetSliceStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
||||
inputRolesString, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
||||
if err != nil {
|
||||
log.Debug("Error getting default roles: ", err)
|
||||
return res, fmt.Errorf(`invalid roles`)
|
||||
} else {
|
||||
inputRoles = strings.Split(inputRolesString, ",")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
user.Roles = strings.Join(inputRoles, ",")
|
||||
@@ -110,10 +114,12 @@ func MagicLinkLoginResolver(ctx context.Context, params model.MagicLinkLoginInpu
|
||||
|
||||
// find the unassigned roles
|
||||
if len(params.Roles) <= 0 {
|
||||
inputRoles, err = memorystore.Provider.GetSliceStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
||||
inputRolesString, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
||||
if err != nil {
|
||||
log.Debug("Error getting default roles: ", err)
|
||||
return res, fmt.Errorf(`invalid default roles`)
|
||||
} else {
|
||||
inputRoles = strings.Split(inputRolesString, ",")
|
||||
}
|
||||
}
|
||||
existingRoles := strings.Split(existingUser.Roles, ",")
|
||||
@@ -127,10 +133,13 @@ func MagicLinkLoginResolver(ctx context.Context, params model.MagicLinkLoginInpu
|
||||
if len(unasignedRoles) > 0 {
|
||||
// check if it contains protected unassigned role
|
||||
hasProtectedRole := false
|
||||
protectedRoles, err := memorystore.Provider.GetSliceStoreEnvVariable(constants.EnvKeyProtectedRoles)
|
||||
protectedRolesString, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyProtectedRoles)
|
||||
protectedRoles := []string{}
|
||||
if err != nil {
|
||||
log.Debug("Error getting protected roles: ", err)
|
||||
return res, err
|
||||
} else {
|
||||
protectedRoles = strings.Split(protectedRolesString, ",")
|
||||
}
|
||||
for _, ur := range unasignedRoles {
|
||||
if utils.StringSliceContains(protectedRoles, ur) {
|
||||
|
@@ -92,10 +92,13 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
||||
|
||||
if len(params.Roles) > 0 {
|
||||
// check if roles exists
|
||||
roles, err := memorystore.Provider.GetSliceStoreEnvVariable(constants.EnvKeyRoles)
|
||||
rolesString, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyRoles)
|
||||
roles := []string{}
|
||||
if err != nil {
|
||||
log.Debug("Error getting roles: ", err)
|
||||
return res, err
|
||||
} else {
|
||||
roles = strings.Split(rolesString, ",")
|
||||
}
|
||||
if !validators.IsValidRoles(roles, params.Roles) {
|
||||
log.Debug("Invalid roles: ", params.Roles)
|
||||
@@ -104,10 +107,12 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
||||
inputRoles = params.Roles
|
||||
}
|
||||
} else {
|
||||
inputRoles, err = memorystore.Provider.GetSliceStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
||||
inputRolesString, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
||||
if err != nil {
|
||||
log.Debug("Error getting default roles: ", err)
|
||||
return res, err
|
||||
} else {
|
||||
inputRoles = strings.Split(inputRolesString, ",")
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -156,13 +156,22 @@ func UpdateUserResolver(ctx context.Context, params model.UpdateUserInput) (*mod
|
||||
inputRoles = append(inputRoles, *item)
|
||||
}
|
||||
|
||||
roles, err := memorystore.Provider.GetSliceStoreEnvVariable(constants.EnvKeyRoles)
|
||||
rolesString, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyRoles)
|
||||
roles := []string{}
|
||||
if err != nil {
|
||||
log.Debug("Error getting roles: ", err)
|
||||
rolesString = ""
|
||||
} else {
|
||||
roles = strings.Split(rolesString, ",")
|
||||
}
|
||||
protectedRoles, err := memorystore.Provider.GetSliceStoreEnvVariable(constants.EnvKeyProtectedRoles)
|
||||
protectedRolesString, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyProtectedRoles)
|
||||
fmt.Println(protectedRolesString)
|
||||
protectedRoles := []string{}
|
||||
if err != nil {
|
||||
log.Debug("Error getting protected roles: ", err)
|
||||
protectedRolesString = ""
|
||||
} else {
|
||||
protectedRoles = strings.Split(protectedRolesString, ",")
|
||||
}
|
||||
|
||||
if !validators.IsValidRoles(inputRoles, append([]string{}, append(roles, protectedRoles...)...)) {
|
||||
|
Reference in New Issue
Block a user