Skip to content

Commit 599b2f9

Browse files
authored
Merge branch 'release/v1.23' into lunny/add_reviewer_notifier_pr_sync2
2 parents 267a317 + b351676 commit 599b2f9

File tree

4 files changed

+48
-25
lines changed

4 files changed

+48
-25
lines changed

routers/web/githttp.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,12 @@
44
package web
55

66
import (
7-
"net/http"
8-
9-
"code.gitea.io/gitea/modules/setting"
107
"code.gitea.io/gitea/modules/web"
118
"code.gitea.io/gitea/routers/web/repo"
129
"code.gitea.io/gitea/services/context"
1310
)
1411

1512
func addOwnerRepoGitHTTPRouters(m *web.Router) {
16-
reqGitSignIn := func(ctx *context.Context) {
17-
if !setting.Service.RequireSignInView {
18-
return
19-
}
20-
// rely on the results of Contexter
21-
if !ctx.IsSigned {
22-
// TODO: support digit auth - which would be Authorization header with digit
23-
ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea"`)
24-
ctx.Error(http.StatusUnauthorized)
25-
}
26-
}
2713
m.Group("/{username}/{reponame}", func() {
2814
m.Methods("POST,OPTIONS", "/git-upload-pack", repo.ServiceUploadPack)
2915
m.Methods("POST,OPTIONS", "/git-receive-pack", repo.ServiceReceivePack)
@@ -36,5 +22,5 @@ func addOwnerRepoGitHTTPRouters(m *web.Router) {
3622
m.Methods("GET,OPTIONS", "/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38,62}}", repo.GetLooseObject)
3723
m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.pack", repo.GetPackFile)
3824
m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.idx", repo.GetIdxFile)
39-
}, optSignInIgnoreCsrf, reqGitSignIn, repo.HTTPGitEnabledHandler, repo.CorsHandler(), context.UserAssignmentWeb())
25+
}, optSignInIgnoreCsrf, repo.HTTPGitEnabledHandler, repo.CorsHandler(), context.UserAssignmentWeb())
4026
}

templates/repo/create.tmpl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@
1010
<div class="ui attached segment">
1111
{{template "base/alert" .}}
1212
{{template "repo/create_helper" .}}
13-
14-
{{if not .CanCreateRepo}}
15-
<div class="ui negative message">
16-
<p>{{ctx.Locale.TrN .MaxCreationLimit "repo.form.reach_limit_of_creation_1" "repo.form.reach_limit_of_creation_n" .MaxCreationLimit}}</p>
17-
</div>
18-
{{end}}
13+
<div id="create-repo-error-message" class="ui negative message tw-text-center tw-hidden"></div>
1914
<div class="inline required field {{if .Err_Owner}}error{{end}}">
2015
<label>{{ctx.Locale.Tr "repo.owner"}}</label>
2116
<div class="ui selection owner dropdown">
@@ -26,7 +21,11 @@
2621
</span>
2722
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
2823
<div class="menu">
29-
<div class="item truncated-item-container" data-value="{{.SignedUser.ID}}" title="{{.SignedUser.Name}}">
24+
<div class="item truncated-item-container" data-value="{{.SignedUser.ID}}" title="{{.SignedUser.Name}}"
25+
{{if not .CanCreateRepo}}
26+
data-create-repo-disallowed-prompt="{{ctx.Locale.TrN .MaxCreationLimit "repo.form.reach_limit_of_creation_1" "repo.form.reach_limit_of_creation_n" .MaxCreationLimit}}"
27+
{{end}}
28+
>
3029
{{ctx.AvatarUtils.Avatar .SignedUser 28 "mini"}}
3130
<span class="truncated-item-name">{{.SignedUser.ShortName 40}}</span>
3231
</div>
@@ -209,7 +208,7 @@
209208
<br>
210209
<div class="inline field">
211210
<label></label>
212-
<button class="ui primary button{{if not .CanCreateRepo}} disabled{{end}}">
211+
<button class="ui primary button">
213212
{{ctx.Locale.Tr "repo.create_repo"}}
214213
</button>
215214
</div>

tests/integration/git_smart_http_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ import (
99
"net/url"
1010
"testing"
1111

12+
"code.gitea.io/gitea/modules/setting"
13+
"code.gitea.io/gitea/modules/test"
14+
1215
"github.com/stretchr/testify/assert"
1316
)
1417

1518
func TestGitSmartHTTP(t *testing.T) {
16-
onGiteaRun(t, testGitSmartHTTP)
19+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
20+
testGitSmartHTTP(t, u)
21+
testRenamedRepoRedirect(t)
22+
})
1723
}
1824

1925
func testGitSmartHTTP(t *testing.T, u *url.URL) {
@@ -66,3 +72,21 @@ func testGitSmartHTTP(t *testing.T, u *url.URL) {
6672
})
6773
}
6874
}
75+
76+
func testRenamedRepoRedirect(t *testing.T) {
77+
defer test.MockVariableValue(&setting.Service.RequireSignInView, true)()
78+
79+
// git client requires to get a 301 redirect response before 401 unauthorized response
80+
req := NewRequest(t, "GET", "/user2/oldrepo1/info/refs")
81+
resp := MakeRequest(t, req, http.StatusMovedPermanently)
82+
redirect := resp.Header().Get("Location")
83+
assert.Equal(t, "/user2/repo1/info/refs", redirect)
84+
85+
req = NewRequest(t, "GET", redirect)
86+
resp = MakeRequest(t, req, http.StatusUnauthorized)
87+
assert.Equal(t, "Unauthorized\n", resp.Body.String())
88+
89+
req = NewRequest(t, "GET", redirect).AddBasicAuth("user2")
90+
resp = MakeRequest(t, req, http.StatusOK)
91+
assert.Contains(t, resp.Body.String(), "65f1bf27bc3bf70f64657658635e66094edbcb4d\trefs/tags/v1.1")
92+
}

web_src/js/features/repo-template.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
22
import {htmlEscape} from 'escape-goat';
3-
import {hideElem, showElem} from '../utils/dom.ts';
3+
import {hideElem, querySingleVisibleElem, showElem, toggleElem} from '../utils/dom.ts';
44

55
const {appSubUrl} = window.config;
66

@@ -21,6 +21,20 @@ export function initRepoTemplateSearch() {
2121
checkTemplate();
2222

2323
const changeOwner = function () {
24+
const elUid = document.querySelector<HTMLInputElement>('#uid');
25+
const elForm = elUid.closest('form');
26+
const elSubmitButton = querySingleVisibleElem<HTMLInputElement>(elForm, '.ui.primary.button');
27+
const elCreateRepoErrorMessage = elForm.querySelector('#create-repo-error-message');
28+
const elOwnerItem = document.querySelector(`.ui.selection.owner.dropdown .menu > .item[data-value="${CSS.escape(elUid.value)}"]`);
29+
hideElem(elCreateRepoErrorMessage);
30+
elSubmitButton.disabled = false;
31+
if (elOwnerItem) {
32+
elCreateRepoErrorMessage.textContent = elOwnerItem.getAttribute('data-create-repo-disallowed-prompt') ?? '';
33+
const hasError = Boolean(elCreateRepoErrorMessage.textContent);
34+
toggleElem(elCreateRepoErrorMessage, hasError);
35+
elSubmitButton.disabled = hasError;
36+
}
37+
2438
$('#repo_template_search')
2539
.dropdown({
2640
apiSettings: {

0 commit comments

Comments
 (0)