mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-21 19:24:31 +00:00
feat(org): add DEFAULT_TEAM_VISIBILITY instance setting (#40151)
Adds an instance-level `DEFAULT_TEAM_VISIBILITY` setting (`private`/`limited`/`public`, default `private`) so administrators can configure the default visibility for newly created teams when it isn't explicitly chosen in the web form or sent via the API. Also fixes a template bug where the "Private" radio was always force-checked on the new-team page regardless of the actual default. Fixes: https://github.com/go-gitea/gitea/issues/40128 ## Verification Tested all three config values (absent/`private`, `public`, `limited`) against both the web form default and the API (`POST /orgs/{org}/teams` without `visibility`) — in each case the correct default was applied. ## Test 1: Key absent in app.ini -> falls back to "private" <img width="3178" height="1312" alt="image" src="https://github.com/user-attachments/assets/7ce87372-eb3e-4f03-84da-fc21ace86eca" /> ## Test 2: DEFAULT_TEAM_VISIBILITY = public <img width="2802" height="1348" alt="image" src="https://github.com/user-attachments/assets/aa1af297-9557-434d-82c6-1af253eec2ab" /> ## Test 3: DEFAULT_TEAM_VISIBILITY = limited <img width="2778" height="1198" alt="image" src="https://github.com/user-attachments/assets/1e66565b-c275-454a-a7d1-66d11ef3b9ee" /> --------- Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
1 parent
1424a2b7c2
commit
bf5c39b310
10 files changed
+33
-6
No files matched your search
@@ -941,6 +941,10 @@ LEVEL = Info
|
||||
;; True will make the membership of the users visible when added to the organisation
|
||||
;DEFAULT_ORG_MEMBER_VISIBLE = false
|
||||
;;
|
||||
;; Either "public", "limited" or "private", default is "private"
|
||||
;; Sets the default visibility for newly created teams within an organization
|
||||
;DEFAULT_TEAM_VISIBILITY = private
|
||||
;;
|
||||
;; Default value for EnableDependencies
|
||||
;; Repositories will use dependencies by default depending on this setting
|
||||
;DEFAULT_ENABLE_DEPENDENCIES = true
|
||||
|
||||
@@ -27,6 +27,7 @@ var Service = struct {
|
||||
DefaultUserVisibilityMode structs.VisibleType `ini:"-"`
|
||||
AllowedUserVisibilityModesSlice AllowedVisibility `ini:"-"`
|
||||
DefaultOrgVisibilityMode structs.VisibleType `ini:"-"`
|
||||
DefaultTeamVisibilityMode structs.VisibleType `ini:"-"`
|
||||
ActiveCodeLives int
|
||||
ResetPwdCodeLives int
|
||||
RegisterEmailConfirm bool
|
||||
@@ -238,6 +239,9 @@ func loadServiceFrom(rootCfg ConfigProvider) {
|
||||
Service.DefaultOrgVisibilityMode = structs.VisibilityModes[defaultOrgVisibility]
|
||||
Service.DefaultOrgMemberVisible = sec.Key("DEFAULT_ORG_MEMBER_VISIBLE").MustBool()
|
||||
|
||||
defaultTeamVisibility := structs.VisibilityString(sec.Key("DEFAULT_TEAM_VISIBILITY").In("private", structs.VisibilityModeKeys()))
|
||||
Service.DefaultTeamVisibilityMode = structs.VisibilityModes[defaultTeamVisibility]
|
||||
|
||||
Service.UserDeleteWithCommentsMaxTime = sec.Key("USER_DELETE_WITH_COMMENTS_MAX_TIME").MustDuration(0)
|
||||
sec.Key("VALID_SITE_URL_SCHEMES").MustString("http,https") // FIXME: INI-MUST-SIDE-EFFECT
|
||||
Service.ValidSiteURLSchemes = sec.Key("VALID_SITE_URL_SCHEMES").Strings(",")
|
||||
|
||||
@@ -62,7 +62,7 @@ type CreateTeamOption struct {
|
||||
UnitsMap map[string]string `json:"units_map"`
|
||||
// Whether the team can create repositories in the organization
|
||||
CanCreateOrgRepo bool `json:"can_create_org_repo"`
|
||||
// Team visibility within the organization. Defaults to "private".
|
||||
// Team visibility within the organization. Defaults to the instance's default team visibility, "private" unless configured.
|
||||
Visibility TeamVisibility `json:"visibility" binding:"In(public,limited,private)"`
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
unit_model "gitea.dev/models/unit"
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/log"
|
||||
"gitea.dev/modules/setting"
|
||||
api "gitea.dev/modules/structs"
|
||||
"gitea.dev/modules/util"
|
||||
"gitea.dev/modules/web"
|
||||
@@ -210,13 +211,17 @@ func CreateTeam(ctx *context.APIContext) {
|
||||
// default:
|
||||
// "$ref": "#/responses/error"
|
||||
form := web.GetForm[*api.CreateTeamOption](ctx)
|
||||
visibility := setting.Service.DefaultTeamVisibilityMode
|
||||
if form.Visibility != "" {
|
||||
visibility = organization.NormalizeTeamVisibility(form.Visibility)
|
||||
}
|
||||
team := &organization.Team{
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
Name: form.Name,
|
||||
Description: form.Description,
|
||||
IncludesAllRepositories: form.IncludesAllRepositories,
|
||||
CanCreateOrgRepo: form.CanCreateOrgRepo,
|
||||
Visibility: organization.NormalizeTeamVisibility(form.Visibility),
|
||||
Visibility: visibility,
|
||||
}
|
||||
_, err := assignTeamPermissionUnits(team, string(form.Permission), form.Units, form.UnitsMap)
|
||||
if err != nil {
|
||||
|
||||
@@ -321,7 +321,7 @@ func NewTeam(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Org.Organization.FullName
|
||||
ctx.Data["PageIsOrgTeams"] = true
|
||||
ctx.Data["PageIsOrgTeamsNew"] = true
|
||||
ctx.Data["Team"] = &org_model.Team{}
|
||||
ctx.Data["Team"] = &org_model.Team{Visibility: setting.Service.DefaultTeamVisibilityMode}
|
||||
ctx.Data["Units"] = unit_model.Units
|
||||
ctx.HTML(http.StatusOK, tplTeamNew)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
<br>
|
||||
<div class="field">
|
||||
<div class="ui radio checkbox">
|
||||
<input type="radio" name="visibility" value="private" {{if or .PageIsOrgTeamsNew .Team.IsPrivate}}checked{{end}}>
|
||||
<input type="radio" name="visibility" value="private" {{if .Team.IsPrivate}}checked{{end}}>
|
||||
<label>{{ctx.Locale.Tr "org.teams.visibility_private"}}</label>
|
||||
<span class="help">{{ctx.Locale.Tr "org.teams.visibility_private_helper"}}</span>
|
||||
</div>
|
||||
|
||||
+1
-1
@@ -5071,7 +5071,7 @@
|
||||
"$ref": "#/components/schemas/TeamVisibility"
|
||||
}
|
||||
],
|
||||
"description": "Team visibility within the organization. Defaults to \"private\"."
|
||||
"description": "Team visibility within the organization. Defaults to the instance's default team visibility, \"private\" unless configured."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
+1
-1
@@ -27547,7 +27547,7 @@
|
||||
}
|
||||
},
|
||||
"visibility": {
|
||||
"description": "Team visibility within the organization. Defaults to \"private\".",
|
||||
"description": "Team visibility within the organization. Defaults to the instance's default team visibility, \"private\" unless configured.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"public",
|
||||
|
||||
@@ -17,8 +17,10 @@ import (
|
||||
"gitea.dev/models/repo"
|
||||
"gitea.dev/models/unittest"
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/setting"
|
||||
"gitea.dev/modules/structs"
|
||||
api "gitea.dev/modules/structs"
|
||||
"gitea.dev/modules/test"
|
||||
"gitea.dev/services/convert"
|
||||
repo_service "gitea.dev/services/repository"
|
||||
"gitea.dev/tests"
|
||||
@@ -110,6 +112,7 @@ func TestAPITeam(t *testing.T) {
|
||||
org = unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 6})
|
||||
|
||||
// Create team.
|
||||
defer test.MockVariableValue(&setting.Service.DefaultTeamVisibilityMode, api.VisibleTypeLimited)()
|
||||
teamToCreate := &api.CreateTeamOption{
|
||||
Name: "team1",
|
||||
Description: "team one",
|
||||
@@ -124,6 +127,7 @@ func TestAPITeam(t *testing.T) {
|
||||
expectedTeamUnitsMap := map[string]string{"repo.code": "read", "repo.issues": "read"}
|
||||
checkTeamResponse(t, "CreateTeam1", apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, api.AccessLevelNameNone, expectedTeamUnitsMap)
|
||||
checkTeamBean(t, apiTeam.ID, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, api.AccessLevelNameNone, expectedTeamUnitsMap)
|
||||
assert.Equal(t, api.TeamVisibilityLimited, apiTeam.Visibility)
|
||||
teamID := apiTeam.ID
|
||||
|
||||
MakeRequest(t, NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/orgs/%s/teams", org.Name), teamToCreate).AddTokenAuth(token), http.StatusConflict)
|
||||
@@ -187,6 +191,7 @@ func TestAPITeam(t *testing.T) {
|
||||
Description: "team two",
|
||||
IncludesAllRepositories: true,
|
||||
UnitsMap: map[string]string{"repo.code": "read", "repo.issues": "write", "repo.wiki": "none"},
|
||||
Visibility: api.TeamVisibilityPrivate,
|
||||
}
|
||||
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/orgs/%s/teams", org.Name), teamToCreate).
|
||||
AddTokenAuth(token)
|
||||
@@ -194,6 +199,7 @@ func TestAPITeam(t *testing.T) {
|
||||
apiTeam = DecodeJSON(t, resp, &api.Team{})
|
||||
checkTeamResponse(t, "CreateTeam2", apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, api.AccessLevelNameNone, teamToCreate.UnitsMap)
|
||||
checkTeamBean(t, apiTeam.ID, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, api.AccessLevelNameNone, teamToCreate.UnitsMap)
|
||||
assert.Equal(t, api.TeamVisibilityPrivate, apiTeam.Visibility)
|
||||
teamID = apiTeam.ID
|
||||
|
||||
// Create a team with permission=write, then edit it to granular permissions later, team's permission should be reset to none
|
||||
|
||||
@@ -304,6 +304,14 @@ func testTeamsPage(t *testing.T) {
|
||||
req = NewRequestf(t, "GET", "/org/%s/teams", org.Name)
|
||||
nonMemberSession.MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
t.Run("NewTeamDefaultVisibility", func(t *testing.T) {
|
||||
defer test.MockVariableValue(&setting.Service.DefaultTeamVisibilityMode, api.VisibleTypeLimited)()
|
||||
req := NewRequestf(t, "GET", "/org/%s/teams/new", org.Name)
|
||||
checked := NewHTMLParser(t, ownerSession.MakeRequest(t, req, http.StatusOK).Body).Find(`input[name="visibility"][checked]`)
|
||||
assert.Equal(t, 1, checked.Length())
|
||||
assert.Equal(t, "limited", checked.AttrOr("value", ""))
|
||||
})
|
||||
|
||||
t.Run("Pagination", func(t *testing.T) {
|
||||
defer test.MockVariableValue(&setting.UI.MembersPagingNum, 2)()
|
||||
assert.Len(t, listTeams(t, ownerSession, "?page=1"), 2)
|
||||
|
||||
Reference in new issue
Block a user