Skip to content

Commit da6e9f6

Browse files
yp05327silverwind
andauthored
Add owner team permission check test (#24096)
Add test for #23675 Should be merged after #24117 --------- Co-authored-by: silverwind <me@silverwind.io>
1 parent 9421063 commit da6e9f6

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

models/organization/org.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,15 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) {
342342
// insert units for team
343343
units := make([]TeamUnit, 0, len(unit.AllRepoUnitTypes))
344344
for _, tp := range unit.AllRepoUnitTypes {
345+
up := perm.AccessModeOwner
346+
if tp == unit.TypeExternalTracker || tp == unit.TypeExternalWiki {
347+
up = perm.AccessModeRead
348+
}
345349
units = append(units, TeamUnit{
346350
OrgID: org.ID,
347351
TeamID: t.ID,
348352
Type: tp,
349-
AccessMode: perm.AccessModeOwner,
353+
AccessMode: up,
350354
})
351355
}
352356

tests/integration/api_org_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import (
1111
"testing"
1212

1313
auth_model "code.gitea.io/gitea/models/auth"
14+
"code.gitea.io/gitea/models/db"
15+
org_model "code.gitea.io/gitea/models/organization"
16+
"code.gitea.io/gitea/models/perm"
17+
unit_model "code.gitea.io/gitea/models/unit"
1418
"code.gitea.io/gitea/models/unittest"
1519
user_model "code.gitea.io/gitea/models/user"
1620
"code.gitea.io/gitea/modules/setting"
@@ -51,6 +55,22 @@ func TestAPIOrgCreate(t *testing.T) {
5155
FullName: org.FullName,
5256
})
5357

58+
// Check owner team permission
59+
ownerTeam, _ := org_model.GetOwnerTeam(db.DefaultContext, apiOrg.ID)
60+
61+
for _, ut := range unit_model.AllRepoUnitTypes {
62+
up := perm.AccessModeOwner
63+
if ut == unit_model.TypeExternalTracker || ut == unit_model.TypeExternalWiki {
64+
up = perm.AccessModeRead
65+
}
66+
unittest.AssertExistsAndLoadBean(t, &org_model.TeamUnit{
67+
OrgID: apiOrg.ID,
68+
TeamID: ownerTeam.ID,
69+
Type: ut,
70+
AccessMode: up,
71+
})
72+
}
73+
5474
req = NewRequestf(t, "GET", "/api/v1/orgs/%s?token=%s", org.UserName, token)
5575
resp = MakeRequest(t, req, http.StatusOK)
5676
DecodeJSON(t, resp, &apiOrg)

0 commit comments

Comments
 (0)