Skip to content

Commit 04ae54f

Browse files
authored
Merge branch 'main' into fix-various
2 parents 3721358 + 1839110 commit 04ae54f

File tree

8 files changed

+40
-23
lines changed

8 files changed

+40
-23
lines changed

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ COMMA := ,
2626
XGO_VERSION := go-1.24.x
2727

2828
AIR_PACKAGE ?= github.com/air-verse/air@v1
29-
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3.2.1
30-
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.7.0
31-
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.0.2
29+
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3
30+
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.8.0
31+
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6
3232
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
33-
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.6.0
34-
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0
33+
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.7.0
34+
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.32.3
3535
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
3636
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1
3737
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1
3838
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1
39-
GOPLS_PACKAGE ?= golang.org/x/tools/[email protected].0
40-
GOPLS_MODERNIZE_PACKAGE ?= golang.org/x/tools/gopls/internal/analysis/modernize/cmd/[email protected].0
39+
GOPLS_PACKAGE ?= golang.org/x/tools/[email protected].1
40+
GOPLS_MODERNIZE_PACKAGE ?= golang.org/x/tools/gopls/internal/analysis/modernize/cmd/[email protected].1
4141

4242
DOCKER_IMAGE ?= gitea/gitea
4343
DOCKER_TAG ?= latest

models/asymkey/gpg_key_add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func AddGPGKey(ctx context.Context, ownerID int64, content, token, signature str
9191
signer, err = openpgp.CheckArmoredDetachedSignature(ekeys, strings.NewReader(token+"\r\n"), strings.NewReader(signature), nil)
9292
}
9393
if err != nil {
94-
log.Error("Unable to validate token signature. Error: %v", err)
94+
log.Debug("AddGPGKey CheckArmoredDetachedSignature failed: %v", err)
9595
return nil, ErrGPGInvalidTokenSignature{
9696
ID: ekeys[0].PrimaryKey.KeyIdString(),
9797
Wrapped: err,

models/asymkey/gpg_key_verify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func VerifyGPGKey(ctx context.Context, ownerID int64, keyID, token, signature st
8585
}
8686

8787
if signer == nil {
88-
log.Error("Unable to validate token signature. Error: %v", err)
88+
log.Debug("VerifyGPGKey failed: no signer")
8989
return "", ErrGPGInvalidTokenSignature{
9090
ID: key.KeyID,
9191
}

models/asymkey/ssh_key_verify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func VerifySSHKey(ctx context.Context, ownerID int64, fingerprint, token, signat
3535
// edge case for Windows based shells that will add CR LF if piped to ssh-keygen command
3636
// see https://github.com/PowerShell/PowerShell/issues/5974
3737
if sshsig.Verify(strings.NewReader(token+"\r\n"), []byte(signature), []byte(key.Content), "gitea") != nil {
38-
log.Error("Unable to validate token signature. Error: %v", err)
38+
log.Debug("VerifySSHKey sshsig.Verify failed: %v", err)
3939
return "", ErrSSHInvalidTokenSignature{
4040
Fingerprint: key.Fingerprint,
4141
}

models/perm/access/repo_permission.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func (p *Permission) IsAdmin() bool {
4242

4343
// HasAnyUnitAccess returns true if the user might have at least one access mode to any unit of this repository.
4444
// It doesn't count the "public(anonymous/everyone) access mode".
45+
// TODO: most calls to this function should be replaced with `HasAnyUnitAccessOrPublicAccess`
4546
func (p *Permission) HasAnyUnitAccess() bool {
4647
for _, v := range p.unitsMode {
4748
if v >= perm_model.AccessModeRead {

routers/api/v1/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func repoAssignment() func(ctx *context.APIContext) {
228228
}
229229
}
230230

231-
if !ctx.Repo.Permission.HasAnyUnitAccess() {
231+
if !ctx.Repo.Permission.HasAnyUnitAccessOrPublicAccess() {
232232
ctx.APIErrorNotFound()
233233
return
234234
}
@@ -1247,7 +1247,7 @@ func Routes() *web.Router {
12471247
}, reqToken())
12481248
m.Get("/raw/*", context.ReferencesGitRepo(), context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetRawFile)
12491249
m.Get("/media/*", context.ReferencesGitRepo(), context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetRawFileOrLFS)
1250-
m.Get("/archive/*", reqRepoReader(unit.TypeCode), repo.GetArchive)
1250+
m.Methods("HEAD,GET", "/archive/*", reqRepoReader(unit.TypeCode), repo.GetArchive)
12511251
m.Combo("/forks").Get(repo.ListForks).
12521252
Post(reqToken(), reqRepoReader(unit.TypeCode), bind(api.CreateForkOption{}), repo.CreateFork)
12531253
m.Post("/merge-upstream", reqToken(), mustNotBeArchived, reqRepoWriter(unit.TypeCode), bind(api.MergeUpstreamRequest{}), repo.MergeUpstream)
@@ -1466,7 +1466,7 @@ func Routes() *web.Router {
14661466
m.Delete("", repo.DeleteAvatar)
14671467
}, reqAdmin(), reqToken())
14681468

1469-
m.Get("/{ball_type:tarball|zipball|bundle}/*", reqRepoReader(unit.TypeCode), repo.DownloadArchive)
1469+
m.Methods("HEAD,GET", "/{ball_type:tarball|zipball|bundle}/*", reqRepoReader(unit.TypeCode), repo.DownloadArchive)
14701470
}, repoAssignment(), checkTokenPublicOnly())
14711471
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryRepository))
14721472

tests/integration/api_repo_archive_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import (
1212
"testing"
1313

1414
auth_model "code.gitea.io/gitea/models/auth"
15+
"code.gitea.io/gitea/models/perm"
1516
repo_model "code.gitea.io/gitea/models/repo"
17+
"code.gitea.io/gitea/models/unit"
1618
"code.gitea.io/gitea/models/unittest"
1719
user_model "code.gitea.io/gitea/models/user"
1820
"code.gitea.io/gitea/tests"
@@ -58,9 +60,12 @@ func TestAPIDownloadArchive(t *testing.T) {
5860

5961
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master", user2.Name, repo.Name))
6062
MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusBadRequest)
63+
64+
t.Run("GitHubStyle", testAPIDownloadArchiveGitHubStyle)
65+
t.Run("PrivateRepo", testAPIDownloadArchivePrivateRepo)
6166
}
6267

63-
func TestAPIDownloadArchive2(t *testing.T) {
68+
func testAPIDownloadArchiveGitHubStyle(t *testing.T) {
6469
defer tests.PrepareTestEnv(t)()
6570

6671
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
@@ -95,7 +100,13 @@ func TestAPIDownloadArchive2(t *testing.T) {
95100
bs, err = io.ReadAll(resp.Body)
96101
assert.NoError(t, err)
97102
assert.Len(t, bs, 382)
103+
}
98104

99-
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master", user2.Name, repo.Name))
100-
MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusBadRequest)
105+
func testAPIDownloadArchivePrivateRepo(t *testing.T) {
106+
_ = repo_model.UpdateRepositoryColsNoAutoTime(t.Context(), &repo_model.Repository{ID: 1, IsPrivate: true}, "is_private")
107+
MakeRequest(t, NewRequest(t, "HEAD", "/api/v1/repos/user2/repo1/archive/master.zip"), http.StatusNotFound)
108+
MakeRequest(t, NewRequest(t, "HEAD", "/api/v1/repos/user2/repo1/zipball/master"), http.StatusNotFound)
109+
_ = repo_model.UpdateRepoUnitPublicAccess(t.Context(), &repo_model.RepoUnit{RepoID: 1, Type: unit.TypeCode, AnonymousAccessMode: perm.AccessModeRead})
110+
MakeRequest(t, NewRequest(t, "HEAD", "/api/v1/repos/user2/repo1/archive/master.zip"), http.StatusOK)
111+
MakeRequest(t, NewRequest(t, "HEAD", "/api/v1/repos/user2/repo1/zipball/master"), http.StatusOK)
101112
}

web_src/js/components/DashboardRepoList.vue

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default defineComponent({
3939
return {
4040
tab,
4141
repos: [],
42-
reposTotalCount: 0,
42+
reposTotalCount: null,
4343
reposFilter,
4444
archivedFilter,
4545
privateFilter,
@@ -113,9 +113,6 @@ export default defineComponent({
113113
const el = document.querySelector('#dashboard-repo-list');
114114
this.changeReposFilter(this.reposFilter);
115115
fomanticQuery(el.querySelector('.ui.dropdown')).dropdown();
116-
nextTick(() => {
117-
this.$refs.search?.focus();
118-
});
119116
120117
this.textArchivedFilterTitles = {
121118
'archived': this.textShowOnlyArchived,
@@ -243,12 +240,20 @@ export default defineComponent({
243240
244241
let response, json;
245242
try {
243+
const firstLoad = this.reposTotalCount === null;
246244
if (!this.reposTotalCount) {
247245
const totalCountSearchURL = `${this.subUrl}/repo/search?count_only=1&uid=${this.uid}&team_id=${this.teamId}&q=&page=1&mode=`;
248246
response = await GET(totalCountSearchURL);
249247
this.reposTotalCount = parseInt(response.headers.get('X-Total-Count') ?? '0');
250248
}
251-
249+
if (firstLoad && this.reposTotalCount) {
250+
nextTick(() => {
251+
// MDN: If there's no focused element, this is the Document.body or Document.documentElement.
252+
if ((document.activeElement === document.body || document.activeElement === document.documentElement)) {
253+
this.$refs.search.focus({preventScroll: true});
254+
}
255+
});
256+
}
252257
response = await GET(searchedURL);
253258
json = await response.json();
254259
} catch {
@@ -350,7 +355,7 @@ export default defineComponent({
350355
<h4 class="ui top attached header tw-flex tw-items-center">
351356
<div class="tw-flex-1 tw-flex tw-items-center">
352357
{{ textMyRepos }}
353-
<span class="ui grey label tw-ml-2">{{ reposTotalCount }}</span>
358+
<span v-if="reposTotalCount" class="ui grey label tw-ml-2">{{ reposTotalCount }}</span>
354359
</div>
355360
<a class="tw-flex tw-items-center muted" :href="subUrl + '/repo/create' + (isOrganization ? '?org=' + organizationId : '')" :data-tooltip-content="textNewRepo">
356361
<svg-icon name="octicon-plus"/>
@@ -421,7 +426,7 @@ export default defineComponent({
421426
</div>
422427
<div v-if="repos.length" class="ui attached table segment tw-rounded-b">
423428
<ul class="repo-owner-name-list">
424-
<li class="tw-flex tw-items-center tw-py-2" v-for="repo, index in repos" :class="{'active': index === activeIndex}" :key="repo.id">
429+
<li class="tw-flex tw-items-center tw-py-2" v-for="(repo, index) in repos" :class="{'active': index === activeIndex}" :key="repo.id">
425430
<a class="repo-list-link muted" :href="repo.link">
426431
<svg-icon :name="repoIcon(repo)" :size="16" class="repo-list-icon"/>
427432
<div class="text truncate">{{ repo.full_name }}</div>

0 commit comments

Comments
 (0)