mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-02 11:27:06 +02:00
fix: make auth source group sync correctly handle team removal (#37161)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -52,6 +52,28 @@ func (s Set[T]) Remove(value T) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// RemoveFromSet removes the specified elements from the set.
|
||||
// Returns the number of elements successfully removed.
|
||||
func (s Set[T]) RemoveFromSet(o Set[T]) (n int) {
|
||||
for value := range o {
|
||||
if s.Remove(value) {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// RemoveFromSlice removes the specified elements from the slice.
|
||||
// Returns the number of elements successfully removed.
|
||||
func (s Set[T]) RemoveFromSlice(o []T) (n int) {
|
||||
for _, value := range o {
|
||||
if s.Remove(value) {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// Values gets a list of all elements in the set.
|
||||
func (s Set[T]) Values() []T {
|
||||
keys := make([]T, 0, len(s))
|
||||
|
||||
@@ -35,4 +35,14 @@ func TestSet(t *testing.T) {
|
||||
assert.False(t, s.Contains("key1"))
|
||||
assert.True(t, s.Contains("key6"))
|
||||
assert.True(t, s.Contains("key7"))
|
||||
|
||||
s = SetOf("a", "b", "c")
|
||||
n := s.RemoveFromSet(SetOf("b", "c", "d"))
|
||||
assert.Equal(t, 2, n)
|
||||
assert.ElementsMatch(t, []string{"a"}, s.Values())
|
||||
|
||||
s = SetOf("a", "b", "c")
|
||||
n = s.RemoveFromSlice([]string{"b", "c", "d"})
|
||||
assert.Equal(t, 2, n)
|
||||
assert.ElementsMatch(t, []string{"a"}, s.Values())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user