Merge pull request #165 from Vicg853/fix/role-update

Unable to update user role fix
This commit is contained in:
Lakhan Samani 2022-05-13 07:38:45 +05:30 committed by GitHub
commit 6209c4d506
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -24,6 +24,12 @@ func updateUserTest(t *testing.T, s TestSetup) {
}) })
user := *signupRes.User user := *signupRes.User
//! - Found out by testing
//! that the 'supplier' role was being accepted by the server
//! even though that it doesn't exist in the database.
//! (checked it by doing fmt.Println() on role envs)
//! But I'm not removing it as there is maybe a reason for it to be be here...
//! - Appart from that, by removing it test returns 'unauthorized' successfully
adminRole := "supplier" adminRole := "supplier"
userRole := "user" userRole := "user"
newRoles := []*string{&adminRole, &userRole} newRoles := []*string{&adminRole, &userRole}

View File

@ -54,8 +54,8 @@ func IsValidOrigin(url string) bool {
// IsValidRoles validates roles // IsValidRoles validates roles
func IsValidRoles(userRoles []string, roles []string) bool { func IsValidRoles(userRoles []string, roles []string) bool {
valid := true valid := true
for _, role := range roles { for _, userRole := range userRoles {
if !StringSliceContains(userRoles, role) { if !StringSliceContains(roles, userRole) {
valid = false valid = false
break break
} }