Skip to content

Commit 5cfd387

Browse files
committed
Merge branch 'main' into fix-archive-link
2 parents 9d32e00 + ffc9879 commit 5cfd387

File tree

86 files changed

+917
-713
lines changed

Some content is hidden

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

86 files changed

+917
-713
lines changed

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(G
110110

111111
LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64
112112

113-
GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/))
114113
GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/))
115114
MIGRATE_TEST_PACKAGES ?= $(shell $(GO) list code.gitea.io/gitea/models/migrations/...)
116115

@@ -423,7 +422,7 @@ lint-go-windows:
423422
lint-go-vet:
424423
@echo "Running go vet..."
425424
@GOOS= GOARCH= $(GO) build code.gitea.io/gitea-vet
426-
@$(GO) vet -vettool=gitea-vet $(GO_PACKAGES)
425+
@$(GO) vet -vettool=gitea-vet ./...
427426

428427
.PHONY: lint-editorconfig
429428
lint-editorconfig:
@@ -779,7 +778,7 @@ generate-backend: $(TAGS_PREREQ) generate-go
779778
.PHONY: generate-go
780779
generate-go: $(TAGS_PREREQ)
781780
@echo "Running go generate..."
782-
@CC= GOOS= GOARCH= $(GO) generate -tags '$(TAGS)' $(GO_PACKAGES)
781+
@CC= GOOS= GOARCH= $(GO) generate -tags '$(TAGS)' ./...
783782

784783
.PHONY: security-check
785784
security-check:

models/issues/pull_list.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ func CanMaintainerWriteToBranch(ctx context.Context, p access_model.Permission,
6262
return true
6363
}
6464

65-
if len(p.Units) < 1 {
65+
// the code below depends on units to get the repository ID, not ideal but just keep it for now
66+
firstUnitRepoID := p.GetFirstUnitRepoID()
67+
if firstUnitRepoID == 0 {
6668
return false
6769
}
6870

69-
prs, err := GetUnmergedPullRequestsByHeadInfo(ctx, p.Units[0].RepoID, branch)
71+
prs, err := GetUnmergedPullRequestsByHeadInfo(ctx, firstUnitRepoID, branch)
7072
if err != nil {
7173
return false
7274
}

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ var migrations = []Migration{
582582
NewMigration("Add commit status summary table", v1_23.AddCommitStatusSummary),
583583
// v296 -> v297
584584
NewMigration("Add missing field of commit status summary table", v1_23.AddCommitStatusSummary2),
585+
// v297 -> v298
586+
NewMigration("Add everyone_access_mode for repo_unit", v1_23.AddRepoUnitEveryoneAccessMode),
585587
}
586588

587589
// GetCurrentDBVersion returns the current db version

models/migrations/v1_11/v111.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func AddBranchProtectionCanPushAndEnableWhitelist(x *xorm.Engine) error {
336336
if err != nil {
337337
return false, err
338338
}
339-
if perm.UnitsMode == nil {
339+
if len(perm.UnitsMode) == 0 {
340340
for _, u := range perm.Units {
341341
if u.Type == UnitTypeCode {
342342
return AccessModeWrite <= perm.AccessMode, nil

models/migrations/v1_23/v297.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_23 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/models/perm"
8+
9+
"xorm.io/xorm"
10+
)
11+
12+
func AddRepoUnitEveryoneAccessMode(x *xorm.Engine) error {
13+
type RepoUnit struct { //revive:disable-line:exported
14+
EveryoneAccessMode perm.AccessMode `xorm:"NOT NULL DEFAULT 0"`
15+
}
16+
return x.Sync(&RepoUnit{})
17+
}

models/organization/team.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ func (t *Team) GetUnitsMap() map[string]string {
130130
m := make(map[string]string)
131131
if t.AccessMode >= perm.AccessModeAdmin {
132132
for _, u := range unit.Units {
133-
m[u.NameKey] = t.AccessMode.String()
133+
m[u.NameKey] = t.AccessMode.ToString()
134134
}
135135
} else {
136136
for _, u := range t.Units {
137-
m[u.Unit().NameKey] = u.AccessMode.String()
137+
m[u.Unit().NameKey] = u.AccessMode.ToString()
138138
}
139139
}
140140
return m
@@ -174,23 +174,27 @@ func (t *Team) LoadMembers(ctx context.Context) (err error) {
174174
return err
175175
}
176176

177-
// UnitEnabled returns if the team has the given unit type enabled
177+
// UnitEnabled returns true if the team has the given unit type enabled
178178
func (t *Team) UnitEnabled(ctx context.Context, tp unit.Type) bool {
179179
return t.UnitAccessMode(ctx, tp) > perm.AccessModeNone
180180
}
181181

182-
// UnitAccessMode returns if the team has the given unit type enabled
182+
// UnitAccessMode returns the access mode for the given unit type, "none" for non-existent units
183183
func (t *Team) UnitAccessMode(ctx context.Context, tp unit.Type) perm.AccessMode {
184+
accessMode, _ := t.UnitAccessModeEx(ctx, tp)
185+
return accessMode
186+
}
187+
188+
func (t *Team) UnitAccessModeEx(ctx context.Context, tp unit.Type) (accessMode perm.AccessMode, exist bool) {
184189
if err := t.LoadUnits(ctx); err != nil {
185190
log.Warn("Error loading team (ID: %d) units: %s", t.ID, err.Error())
186191
}
187-
188-
for _, unit := range t.Units {
189-
if unit.Type == tp {
190-
return unit.AccessMode
192+
for _, u := range t.Units {
193+
if u.Type == tp {
194+
return u.AccessMode, true
191195
}
192196
}
193-
return perm.AccessModeNone
197+
return perm.AccessModeNone, false
194198
}
195199

196200
// IsUsableTeamName tests if a name could be as team name

models/perm/access/access.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ func accessLevel(ctx context.Context, user *user_model.User, repo *repo_model.Re
6363
}
6464

6565
func maxAccessMode(modes ...perm.AccessMode) perm.AccessMode {
66-
max := perm.AccessModeNone
66+
maxMode := perm.AccessModeNone
6767
for _, mode := range modes {
68-
if mode > max {
69-
max = mode
70-
}
68+
maxMode = max(maxMode, mode)
7169
}
72-
return max
70+
return maxMode
7371
}
7472

7573
type userAccess struct {

0 commit comments

Comments
 (0)