Skip to content

Commit 5164dc3

Browse files
Merge branch 'main' into fix-tmpl
2 parents f6d4698 + a100ac3 commit 5164dc3

File tree

36 files changed

+1167
-1009
lines changed

36 files changed

+1167
-1009
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_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/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-
}

modules/repository/init.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ import (
1111
"strings"
1212

1313
issues_model "code.gitea.io/gitea/models/issues"
14-
repo_model "code.gitea.io/gitea/models/repo"
15-
"code.gitea.io/gitea/modules/git"
16-
"code.gitea.io/gitea/modules/gitrepo"
1714
"code.gitea.io/gitea/modules/label"
18-
"code.gitea.io/gitea/modules/log"
1915
"code.gitea.io/gitea/modules/options"
2016
"code.gitea.io/gitea/modules/setting"
2117
"code.gitea.io/gitea/modules/util"
@@ -121,29 +117,6 @@ func LoadRepoConfig() error {
121117
return nil
122118
}
123119

124-
func CheckInitRepository(ctx context.Context, repo *repo_model.Repository) (err error) {
125-
// Somehow the directory could exist.
126-
isExist, err := gitrepo.IsRepositoryExist(ctx, repo)
127-
if err != nil {
128-
log.Error("Unable to check if %s exists. Error: %v", repo.FullName(), err)
129-
return err
130-
}
131-
if isExist {
132-
return repo_model.ErrRepoFilesAlreadyExist{
133-
Uname: repo.OwnerName,
134-
Name: repo.Name,
135-
}
136-
}
137-
138-
// Init git bare new repository.
139-
if err = git.InitRepository(ctx, repo.RepoPath(), true, repo.ObjectFormatName); err != nil {
140-
return fmt.Errorf("git.InitRepository: %w", err)
141-
} else if err = gitrepo.CreateDelegateHooks(ctx, repo); err != nil {
142-
return fmt.Errorf("createDelegateHooks: %w", err)
143-
}
144-
return nil
145-
}
146-
147120
// InitializeLabels adds a label set to a repository using a template
148121
func InitializeLabels(ctx context.Context, id int64, labelTemplate string, isOrg bool) error {
149122
list, err := LoadTemplateLabelsByDisplayName(labelTemplate)

0 commit comments

Comments
 (0)