feat(org): add team visibility so org members can discover teams (#37680)

Closes #37670.

Today, org members in Gitea only see teams they're a member of. In
larger orgs that hurts onboarding and discoverability — there's no way
to look up which team owns what without asking around. GitHub solves
this with a per-team visibility setting; this PR brings the same model
to Gitea.

## What changes

- Every team gets a `visibility` setting:
- `private` *(default)* — only team members and org owners can see the
team. Same as today's behavior.
- `limited` — listable by any member of the organization. Members and
the repos the team has access to are visible too. Non-org-members still
see nothing.
  - `public` — listable by any signed-in user.
- The Owners team visibility is fixed and cannot be changed via
settings.
- Existing teams default to `private`, so this is a no-op for anyone who
doesn't change anything.

## API

- `Team`, `CreateTeamOption`, `EditTeamOption` all gain a `visibility`
field (string enum: `private` | `limited` | `public`).
- `GET /orgs/{org}/teams` and `/orgs/{org}/teams/search` now apply the
same visibility rules as the web UI:
  - site admins and org owners still see every team
- other org members see their own teams plus any `limited` or `public`
team
  - `private` teams are no longer leaked through these endpoints
- Swagger/OpenAPI specs regenerated.

## UI

View from admin2 (not an owner):
<img width="1669" height="726"
src="https://github.com/user-attachments/assets/daf4bccb-644b-4426-b178-71963aeaf73b"
/>

View from admin (owner):

<img width="2559" height="863"
src="https://github.com/user-attachments/assets/4f22cebc-e9df-4fd2-8ed4-724d31fadb7a"
/>

---------

Signed-off-by: bircni <bircni@icloud.com>
Co-authored-by: TheFox0x7 <thefox0x7@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
bircni
2026-06-14 21:07:25 +02:00
committed by GitHub
parent 80ca22a9ef
commit 55250407dd
31 changed files with 850 additions and 144 deletions
+53 -5
View File
@@ -12,9 +12,9 @@ import (
func TestDeriveEnumName_hit(t *testing.T) {
key := EnumKey([]any{"red", "green", "blue"})
astMap := map[string]string{key: "Color"}
astMap := map[string][]string{key: {"Color"}}
usages := []enumUsage{{schemaName: "Paint", propName: "color"}}
got, err := deriveEnumName(key, usages, astMap)
got, err := deriveEnumName(key, "", usages, astMap)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@@ -26,7 +26,7 @@ func TestDeriveEnumName_hit(t *testing.T) {
func TestDeriveEnumName_miss(t *testing.T) {
key := EnumKey([]any{"x", "y"})
usages := []enumUsage{{schemaName: "Thing", propName: "kind"}}
_, err := deriveEnumName(key, usages, map[string]string{})
_, err := deriveEnumName(key, "", usages, map[string][]string{})
if err == nil {
t.Fatal("expected miss error, got nil")
}
@@ -64,7 +64,7 @@ func TestExtractSharedEnums_usesASTMap(t *testing.T) {
},
},
}
astMap := map[string]string{EnumKey([]any{"red", "green", "blue"}): "Color"}
astMap := map[string][]string{EnumKey([]any{"red", "green", "blue"}): {"Color"}}
if err := extractSharedEnums(doc, astMap); err != nil {
t.Fatalf("extractSharedEnums: %v", err)
}
@@ -139,6 +139,54 @@ func TestFixFileSchemas_recursesIntoNested(t *testing.T) {
}
}
func TestExtractEnumTypeName_TeamVisibility(t *testing.T) {
enum := []any{"public", "limited", "private"}
key := EnumKey(enum)
astMap := map[string][]string{key: {"UserVisibility", "TeamVisibility"}}
schema := &openapi3.Schema{
Type: &openapi3.Types{"string"},
Enum: enum,
Extensions: map[string]any{
"x-go-enum-desc": "public TeamVisibilityPublic\nlimited TeamVisibilityLimited\nprivate TeamVisibilityPrivate",
},
}
if got := extractEnumTypeName(schema, astMap); got != "TeamVisibility" {
t.Fatalf("got %q, want %q", got, "TeamVisibility")
}
}
func TestExtractEnumTypeName_ambiguousPrefixTie(t *testing.T) {
enum := []any{"one", "two"}
key := EnumKey(enum)
astMap := map[string][]string{key: {"AB", "AC"}}
schema := &openapi3.Schema{
Type: &openapi3.Types{"string"},
Enum: enum,
Extensions: map[string]any{
"x-go-enum-desc": "one ABOne\ntwo ACTwo",
},
}
if got := extractEnumTypeName(schema, astMap); got != "" {
t.Fatalf("got %q, want empty string for ambiguous tie", got)
}
}
func TestExtractEnumTypeName_rejectsIncidentalPrefix(t *testing.T) {
enum := []any{"a", "b"}
key := EnumKey(enum)
astMap := map[string][]string{key: {"Alpha", "Alphabet"}}
schema := &openapi3.Schema{
Type: &openapi3.Types{"string"},
Enum: enum,
Extensions: map[string]any{
"x-go-enum-desc": "a AlphabetA\nb AlphabetB",
},
}
if got := extractEnumTypeName(schema, astMap); got != "Alphabet" {
t.Fatalf("got %q, want %q", got, "Alphabet")
}
}
func TestExtractSharedEnums_missReturnsError(t *testing.T) {
doc := &openapi3.T{
Components: &openapi3.Components{
@@ -164,7 +212,7 @@ func TestExtractSharedEnums_missReturnsError(t *testing.T) {
},
},
}
if err := extractSharedEnums(doc, map[string]string{}); err == nil {
if err := extractSharedEnums(doc, map[string][]string{}); err == nil {
t.Fatal("expected miss error")
}
}