diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-04-17 23:58:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-17 15:58:37 +0000 |
commit | 3feba9f1f44156c256a30d25ad1c25f751819c94 (patch) | |
tree | 77d9575edc49e625b54f5358d67dba0764b1a553 /services/convert | |
parent | bafb80f80d5505b03e5994d1ea6e2dab10052fe1 (diff) | |
download | gitea-3feba9f1f44156c256a30d25ad1c25f751819c94.tar.gz gitea-3feba9f1f44156c256a30d25ad1c25f751819c94.zip |
Allow everyone to read or write a wiki by a repo unit setting (#30495)
Replace #6312
Help #5833
Wiki solution for #639
Diffstat (limited to 'services/convert')
-rw-r--r-- | services/convert/convert.go | 2 | ||||
-rw-r--r-- | services/convert/repository.go | 11 | ||||
-rw-r--r-- | services/convert/user.go | 4 |
3 files changed, 9 insertions, 8 deletions
diff --git a/services/convert/convert.go b/services/convert/convert.go index 5df0303646..3b6139d2fe 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -336,7 +336,7 @@ func ToTeams(ctx context.Context, teams []*organization.Team, loadOrgs bool) ([] Description: t.Description, IncludesAllRepositories: t.IncludesAllRepositories, CanCreateOrgRepo: t.CanCreateOrgRepo, - Permission: t.AccessMode.String(), + Permission: t.AccessMode.ToString(), Units: t.GetUnitNames(), UnitsMap: t.GetUnitsMap(), } diff --git a/services/convert/repository.go b/services/convert/repository.go index 39efd304a9..3b293fe550 100644 --- a/services/convert/repository.go +++ b/services/convert/repository.go @@ -25,12 +25,13 @@ func ToRepo(ctx context.Context, repo *repo_model.Repository, permissionInRepo a func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInRepo access_model.Permission, isParent bool) *api.Repository { var parent *api.Repository - if permissionInRepo.Units == nil && permissionInRepo.UnitsMode == nil { - // If Units and UnitsMode are both nil, it means that it's a hard coded permission, - // like access_model.Permission{AccessMode: perm.AccessModeAdmin}. - // So we need to load units for the repo, or UnitAccessMode will always return perm.AccessModeNone. + if !permissionInRepo.HasUnits() && permissionInRepo.AccessMode > perm.AccessModeNone { + // If units is empty, it means that it's a hard-coded permission, like access_model.Permission{AccessMode: perm.AccessModeAdmin} + // So we need to load units for the repo, otherwise UnitAccessMode will just return perm.AccessModeNone. + // TODO: this logic is still not right (because unit modes are not correctly prepared) + // the caller should prepare a proper "permission" before calling this function. _ = repo.LoadUnits(ctx) // the error is not important, so ignore it - permissionInRepo.Units = repo.Units + permissionInRepo.SetUnitsWithDefaultAccessMode(repo.Units, permissionInRepo.AccessMode) } cloneLink := repo.CloneLink() diff --git a/services/convert/user.go b/services/convert/user.go index 1a2733d91e..2957c58b14 100644 --- a/services/convert/user.go +++ b/services/convert/user.go @@ -103,7 +103,7 @@ func User2UserSettings(user *user_model.User) api.UserSettings { func ToUserAndPermission(ctx context.Context, user, doer *user_model.User, accessMode perm.AccessMode) api.RepoCollaboratorPermission { return api.RepoCollaboratorPermission{ User: ToUser(ctx, user, doer), - Permission: accessMode.String(), - RoleName: accessMode.String(), + Permission: accessMode.ToString(), + RoleName: accessMode.ToString(), } } |