Skip to content

Commit 8ea9eb3

Browse files
committed
Enable search only for CDI version above 2.20
1 parent 7466ef3 commit 8ea9eb3

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

recipe/dashboard/api/implementation.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package api
1717

1818
import (
19+
"strconv"
20+
1921
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
2022
"github.com/supertokens/supertokens-golang/supertokens"
2123
)
@@ -52,6 +54,19 @@ func MakeAPIImplementation() dashboardmodels.APIInterface {
5254

5355
authMode := string(options.Config.AuthMode)
5456

57+
isSearchEnabled := false
58+
querier, err := supertokens.GetNewQuerierInstanceOrThrowError("")
59+
if err != nil {
60+
return "", err
61+
}
62+
cdiVersion, err := querier.GetQuerierAPIVersion()
63+
if err != nil {
64+
return "", err
65+
}
66+
if maxVersion(cdiVersion, "2.20") == "2.20" {
67+
isSearchEnabled = true
68+
}
69+
5570
return `
5671
<html>
5772
<head>
@@ -61,6 +76,7 @@ func MakeAPIImplementation() dashboardmodels.APIInterface {
6176
window.dashboardAppPath = "` + dashboardAppPath + `"
6277
window.connectionURI = "` + connectionURI + `"
6378
window.authMode = "` + authMode + `"
79+
window.isSearchEnabled = "` + strconv.FormatBool(isSearchEnabled) + `"
6480
</script>
6581
<script defer src="` + bundleDomain + `/static/js/bundle.js"></script></head>
6682
<link href="` + bundleDomain + `/static/css/main.css" rel="stylesheet" type="text/css">

recipe/dashboard/api/utils.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,25 @@ func getUsersWithSearch(timeJoinedOrder string, paginationToken *string, limit *
233233

234234
return result, nil
235235
}
236+
237+
func maxVersion(version1 string, version2 string) string {
238+
var splittedv1 = strings.Split(version1, ".")
239+
var splittedv2 = strings.Split(version2, ".")
240+
var minLength = len(splittedv1)
241+
if minLength > len(splittedv2) {
242+
minLength = len(splittedv2)
243+
}
244+
for i := 0; i < minLength; i++ {
245+
var v1, _ = strconv.Atoi(splittedv1[i])
246+
var v2, _ = strconv.Atoi(splittedv2[i])
247+
if v1 > v2 {
248+
return version1
249+
} else if v2 > v1 {
250+
return version2
251+
}
252+
}
253+
if len(splittedv1) >= len(splittedv2) {
254+
return version1
255+
}
256+
return version2
257+
}

0 commit comments

Comments
 (0)