feat: move to a more robust way of checking if element in slice (#4001)

This commit is contained in:
Kevin D'souza
2025-07-26 09:25:34 +05:30
committed by Yang Luo
parent ac39722687
commit 2d6de216b8
3 changed files with 5 additions and 15 deletions

View File

@@ -807,7 +807,7 @@ func UpdateUser(id string, user *User, columns []string, isAdmin bool) (bool, er
columns = append(columns, "deleted_time")
}
if util.ContainsString(columns, "groups") {
if util.InSlice(columns, "groups") {
_, err := userEnforcer.UpdateGroupsForUser(user.GetId(), user.Groups)
if err != nil {
return false, err

View File

@@ -14,7 +14,7 @@
package util
import "sort"
import "slices"
func DeleteVal(values []string, val string) []string {
newValues := []string{}
@@ -38,18 +38,8 @@ func ReplaceVal(values []string, oldVal string, newVal string) []string {
return newValues
}
func ContainsString(values []string, val string) bool {
sort.Strings(values)
return sort.SearchStrings(values, val) != len(values)
}
func InSlice(slice []string, elem string) bool {
for _, val := range slice {
if val == elem {
return true
}
}
return false
return slices.Contains(slice, elem)
}
func ReturnAnyNotEmpty(strs ...string) string {

View File

@@ -54,10 +54,10 @@ func IsPhoneValid(phone string, countryCode string) bool {
}
func IsPhoneAllowInRegin(countryCode string, allowRegions []string) bool {
if ContainsString(allowRegions, "All") {
if InSlice(allowRegions, "All") {
return true
}
return ContainsString(allowRegions, countryCode)
return InSlice(allowRegions, countryCode)
}
func IsRegexp(s string) (bool, error) {