Skip to content

Commit 10cc6b9

Browse files
authored
Merge branch 'main' into feat/publish-ghcr-io
2 parents 9807d69 + fd7c364 commit 10cc6b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1257
-1078
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/assets/*.json linguist-generated
55
/public/assets/img/svg/*.svg linguist-generated
66
/templates/swagger/v1_json.tmpl linguist-generated
7+
/options/fileicon/** linguist-generated
78
/vendor/** -text -eol linguist-vendored
89
/web_src/js/vendor/** -text -eol linguist-vendored
910
Dockerfile.* linguist-language=Dockerfile

models/git/branch.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ func GetDeletedBranchByID(ctx context.Context, repoID, branchID int64) (*Branch,
235235
return &branch, nil
236236
}
237237

238+
func DeleteRepoBranches(ctx context.Context, repoID int64) error {
239+
_, err := db.GetEngine(ctx).Where("repo_id=?", repoID).Delete(new(Branch))
240+
return err
241+
}
242+
238243
func DeleteBranches(ctx context.Context, repoID, doerID int64, branchIDs []int64) error {
239244
return db.WithTx(ctx, func(ctx context.Context) error {
240245
branches := make([]*Branch, 0, len(branchIDs))

models/issues/issue_update.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"code.gitea.io/gitea/models/db"
1313
"code.gitea.io/gitea/models/organization"
14-
"code.gitea.io/gitea/models/perm"
1514
access_model "code.gitea.io/gitea/models/perm/access"
1615
project_model "code.gitea.io/gitea/models/project"
1716
repo_model "code.gitea.io/gitea/models/repo"
@@ -612,7 +611,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u
612611
unittype = unit.TypePullRequests
613612
}
614613
for _, team := range teams {
615-
if team.AccessMode >= perm.AccessModeAdmin {
614+
if team.HasAdminAccess() {
616615
checked = append(checked, team.ID)
617616
resolved[issue.Repo.Owner.LowerName+"/"+team.LowerName] = true
618617
continue

models/organization/org.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,6 @@ func (org *Organization) HomeLink() string {
178178
return org.AsUser().HomeLink()
179179
}
180180

181-
// CanCreateRepo returns if user login can create a repository
182-
// NOTE: functions calling this assume a failure due to repository count limit; if new checks are added, those functions should be revised
183-
func (org *Organization) CanCreateRepo() bool {
184-
return org.AsUser().CanCreateRepo()
185-
}
186-
187181
// FindOrgMembersOpts represensts find org members conditions
188182
type FindOrgMembersOpts struct {
189183
db.ListOptions

models/organization/org_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func IsOrganizationAdmin(ctx context.Context, orgID, uid int64) (bool, error) {
7878
return false, err
7979
}
8080
for _, t := range teams {
81-
if t.AccessMode >= perm.AccessModeAdmin {
81+
if t.HasAdminAccess() {
8282
return true, nil
8383
}
8484
}

models/organization/team.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (t *Team) LoadUnits(ctx context.Context) (err error) {
113113

114114
// GetUnitNames returns the team units names
115115
func (t *Team) GetUnitNames() (res []string) {
116-
if t.AccessMode >= perm.AccessModeAdmin {
116+
if t.HasAdminAccess() {
117117
return unit.AllUnitKeyNames()
118118
}
119119

@@ -126,7 +126,7 @@ func (t *Team) GetUnitNames() (res []string) {
126126
// GetUnitsMap returns the team units permissions
127127
func (t *Team) GetUnitsMap() map[string]string {
128128
m := make(map[string]string)
129-
if t.AccessMode >= perm.AccessModeAdmin {
129+
if t.HasAdminAccess() {
130130
for _, u := range unit.Units {
131131
m[u.NameKey] = t.AccessMode.ToString()
132132
}
@@ -153,6 +153,10 @@ func (t *Team) IsMember(ctx context.Context, userID int64) bool {
153153
return isMember
154154
}
155155

156+
func (t *Team) HasAdminAccess() bool {
157+
return t.AccessMode >= perm.AccessModeAdmin
158+
}
159+
156160
// LoadMembers returns paginated members in team of organization.
157161
func (t *Team) LoadMembers(ctx context.Context) (err error) {
158162
t.Members, err = GetTeamMembers(ctx, &SearchMembersOptions{
@@ -238,22 +242,6 @@ func GetTeamByID(ctx context.Context, teamID int64) (*Team, error) {
238242
return t, nil
239243
}
240244

241-
// GetTeamNamesByID returns team's lower name from a list of team ids.
242-
func GetTeamNamesByID(ctx context.Context, teamIDs []int64) ([]string, error) {
243-
if len(teamIDs) == 0 {
244-
return []string{}, nil
245-
}
246-
247-
var teamNames []string
248-
err := db.GetEngine(ctx).Table("team").
249-
Select("lower_name").
250-
In("id", teamIDs).
251-
Asc("name").
252-
Find(&teamNames)
253-
254-
return teamNames, err
255-
}
256-
257245
// IncrTeamRepoNum increases the number of repos for the given team by 1
258246
func IncrTeamRepoNum(ctx context.Context, teamID int64) error {
259247
_, err := db.GetEngine(ctx).Incr("num_repos").ID(teamID).Update(new(Team))

models/perm/access/repo_permission.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
331331

332332
// if user in an owner team
333333
for _, team := range teams {
334-
if team.AccessMode >= perm_model.AccessModeAdmin {
334+
if team.HasAdminAccess() {
335335
perm.AccessMode = perm_model.AccessModeOwner
336336
perm.unitsMode = nil
337337
return perm, nil
@@ -399,7 +399,7 @@ func IsUserRepoAdmin(ctx context.Context, repo *repo_model.Repository, user *use
399399
}
400400

401401
for _, team := range teams {
402-
if team.AccessMode >= perm_model.AccessModeAdmin {
402+
if team.HasAdminAccess() {
403403
return true, nil
404404
}
405405
}

models/repo/release.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,3 +558,8 @@ func FindTagsByCommitIDs(ctx context.Context, repoID int64, commitIDs ...string)
558558
}
559559
return res, nil
560560
}
561+
562+
func DeleteRepoReleases(ctx context.Context, repoID int64) error {
563+
_, err := db.GetEngine(ctx).Where("repo_id = ?", repoID).Delete(new(Release))
564+
return err
565+
}

models/repo/update.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,31 +111,31 @@ func (err ErrRepoFilesAlreadyExist) Unwrap() error {
111111
return util.ErrAlreadyExist
112112
}
113113

114-
// CheckCreateRepository check if could created a repository
115-
func CheckCreateRepository(ctx context.Context, doer, u *user_model.User, name string, overwriteOrAdopt bool) error {
116-
if !doer.CanCreateRepo() {
117-
return ErrReachLimitOfRepo{u.MaxRepoCreation}
114+
// CheckCreateRepository check if doer could create a repository in new owner
115+
func CheckCreateRepository(ctx context.Context, doer, owner *user_model.User, name string, overwriteOrAdopt bool) error {
116+
if !doer.CanCreateRepoIn(owner) {
117+
return ErrReachLimitOfRepo{owner.MaxRepoCreation}
118118
}
119119

120120
if err := IsUsableRepoName(name); err != nil {
121121
return err
122122
}
123123

124-
has, err := IsRepositoryModelOrDirExist(ctx, u, name)
124+
has, err := IsRepositoryModelOrDirExist(ctx, owner, name)
125125
if err != nil {
126126
return fmt.Errorf("IsRepositoryExist: %w", err)
127127
} else if has {
128-
return ErrRepoAlreadyExist{u.Name, name}
128+
return ErrRepoAlreadyExist{owner.Name, name}
129129
}
130130

131-
repoPath := RepoPath(u.Name, name)
131+
repoPath := RepoPath(owner.Name, name)
132132
isExist, err := util.IsExist(repoPath)
133133
if err != nil {
134134
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
135135
return err
136136
}
137137
if !overwriteOrAdopt && isExist {
138-
return ErrRepoFilesAlreadyExist{u.Name, name}
138+
return ErrRepoFilesAlreadyExist{owner.Name, name}
139139
}
140140
return nil
141141
}

models/unit/unit.go

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@ type Type int
2020

2121
// Enumerate all the unit types
2222
const (
23-
TypeInvalid Type = iota // 0 invalid
24-
TypeCode // 1 code
25-
TypeIssues // 2 issues
26-
TypePullRequests // 3 PRs
27-
TypeReleases // 4 Releases
28-
TypeWiki // 5 Wiki
29-
TypeExternalWiki // 6 ExternalWiki
30-
TypeExternalTracker // 7 ExternalTracker
31-
TypeProjects // 8 Projects
32-
TypePackages // 9 Packages
33-
TypeActions // 10 Actions
23+
TypeInvalid Type = iota // 0 invalid
24+
25+
TypeCode // 1 code
26+
TypeIssues // 2 issues
27+
TypePullRequests // 3 PRs
28+
TypeReleases // 4 Releases
29+
TypeWiki // 5 Wiki
30+
TypeExternalWiki // 6 ExternalWiki
31+
TypeExternalTracker // 7 ExternalTracker
32+
TypeProjects // 8 Projects
33+
TypePackages // 9 Packages
34+
TypeActions // 10 Actions
35+
36+
// FIXME: TEAM-UNIT-PERMISSION: the team unit "admin" permission's design is not right, when a new unit is added in the future,
37+
// admin team won't inherit the correct admin permission for the new unit, need to have a complete fix before adding any new unit.
3438
)
3539

3640
// Value returns integer value for unit type (used by template)
@@ -380,20 +384,3 @@ func AllUnitKeyNames() []string {
380384
}
381385
return res
382386
}
383-
384-
// MinUnitAccessMode returns the minial permission of the permission map
385-
func MinUnitAccessMode(unitsMap map[Type]perm.AccessMode) perm.AccessMode {
386-
res := perm.AccessModeNone
387-
for t, mode := range unitsMap {
388-
// Don't allow `TypeExternal{Tracker,Wiki}` to influence this as they can only be set to READ perms.
389-
if t == TypeExternalTracker || t == TypeExternalWiki {
390-
continue
391-
}
392-
393-
// get the minial permission great than AccessModeNone except all are AccessModeNone
394-
if mode > perm.AccessModeNone && (res == perm.AccessModeNone || mode < res) {
395-
res = mode
396-
}
397-
}
398-
return res
399-
}

0 commit comments

Comments
 (0)