Skip to content

Commit 3a032cc

Browse files
melegiulsvenseeberg
andcommitted
Replace funk package by custom utility
Co-authored-by: Sven Seeberg <[email protected]> Co-authored-by: Giuliano Mele <[email protected]>
1 parent 673df99 commit 3a032cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+58
-5585
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ require (
106106
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
107107
github.com/stretchr/testify v1.7.0
108108
github.com/syndtr/goleveldb v1.0.0
109-
github.com/thoas/go-funk v0.8.0
110109
github.com/tstranex/u2f v1.0.0
111110
github.com/ulikunitz/xz v0.5.10 // indirect
112111
github.com/unknwon/com v1.0.1

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,8 +1018,6 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
10181018
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
10191019
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
10201020
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
1021-
github.com/thoas/go-funk v0.8.0 h1:JP9tKSvnpFVclYgDM0Is7FD9M4fhPvqA0s0BsXmzSRQ=
1022-
github.com/thoas/go-funk v0.8.0/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
10231021
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
10241022
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
10251023
github.com/tinylib/msgp v1.1.0/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=

modules/auth/ldap/ldap.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
"strings"
1515

1616
"code.gitea.io/gitea/modules/log"
17+
"code.gitea.io/gitea/modules/util"
1718

1819
"github.com/go-ldap/ldap/v3"
19-
"github.com/thoas/go-funk"
2020
)
2121

2222
// SecurityProtocol protocol type
@@ -273,7 +273,7 @@ func (ls *Source) mapLdapGroupsToTeams() map[string]map[string][]string {
273273
ldapGroupsToTeams := make(map[string]map[string][]string)
274274
err := json.Unmarshal([]byte(ls.TeamGroupMap), &ldapGroupsToTeams)
275275
if err != nil {
276-
log.Debug("Failed to unmarshall LDAP teams map: %v", err)
276+
log.Error("Failed to unmarshall LDAP teams map: %v", err)
277277
return ldapGroupsToTeams
278278
}
279279
return ldapGroupsToTeams
@@ -287,11 +287,11 @@ func (ls *Source) getMappedTeams(l *ldap.Conn, uid string) (map[string][]string,
287287
// unmarshall LDAP group team map from configs
288288
ldapGroupsToTeams := ls.mapLdapGroupsToTeams()
289289
// select all LDAP groups from settings
290-
allLdapGroups := funk.Keys(ldapGroupsToTeams).([]string)
290+
allLdapGroups := util.KeysString(ldapGroupsToTeams).([]string)
291291
// contains LDAP config groups, which the user is a member of
292-
usersLdapGroupsToAdd := funk.IntersectString(allLdapGroups, usersLdapGroups)
292+
usersLdapGroupsToAdd := util.IntersectString(allLdapGroups, usersLdapGroups)
293293
// contains LDAP config groups, which the user is not a member of
294-
usersLdapGroupToRemove, _ := funk.DifferenceString(allLdapGroups, usersLdapGroups)
294+
usersLdapGroupToRemove := util.DifferenceString(allLdapGroups, usersLdapGroups)
295295
for _, groupToAdd := range usersLdapGroupsToAdd {
296296
for k, v := range ldapGroupsToTeams[groupToAdd] {
297297
teamsToAdd[k] = v

modules/util/map.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package util
6+
7+
import (
8+
"fmt"
9+
"reflect"
10+
)
11+
12+
// KeysString returns a slice of keys from a map, dict must be a map
13+
func KeysString(dict interface{}) interface{} {
14+
value := reflect.ValueOf(dict)
15+
valueType := value.Type()
16+
if value.Kind() == reflect.Map {
17+
keys := value.MapKeys()
18+
length := len(keys)
19+
resultSlice := reflect.MakeSlice(reflect.SliceOf(valueType.Key()), length, length)
20+
for i, key := range keys {
21+
resultSlice.Index(i).Set(key)
22+
}
23+
return resultSlice.Interface()
24+
}
25+
panic(fmt.Sprintf("Type %s is not supported by KeysString", valueType.String()))
26+
}

modules/util/slice.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package util
6+
7+
// IntersectString returns the intersection of the two string slices
8+
func IntersectString(a, b []string) []string {
9+
var intersection []string
10+
for _, v := range a {
11+
if ExistsInSlice(v, b) && !ExistsInSlice(v, intersection) {
12+
intersection = append(intersection, v)
13+
}
14+
}
15+
return intersection
16+
}
17+
18+
// DifferenceString returns all elements of slice a which are not present in slice b
19+
func DifferenceString(a, b []string) []string {
20+
var difference []string
21+
for _, v := range a {
22+
if !ExistsInSlice(v, b) && !ExistsInSlice(v, difference) {
23+
difference = append(difference, v)
24+
}
25+
}
26+
return difference
27+
}

vendor/github.com/thoas/go-funk/.gitignore

Lines changed: 0 additions & 27 deletions
This file was deleted.

vendor/github.com/thoas/go-funk/.travis.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

vendor/github.com/thoas/go-funk/CHANGELOG.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

vendor/github.com/thoas/go-funk/LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

vendor/github.com/thoas/go-funk/Makefile

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)