Skip to content

Commit 68bb213

Browse files
authored
Merge branch 'main' into sync-git-hook
2 parents d1b3d1c + e2a59c5 commit 68bb213

File tree

21 files changed

+104
-16
lines changed

21 files changed

+104
-16
lines changed

docs/content/doc/installation/with-docker.en-us.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,16 @@ sudo -u git ssh-keygen -t rsa -b 4096 -C "Gitea Host Key"
333333
In the next step a file named `/app/gitea/gitea` (with executable permissions) needs to be created on the host. This file will issue the SSH forwarding from the host to the container. Add the following contents to `/app/gitea/gitea`:
334334

335335
```bash
336+
#!/bin/sh
336337
ssh -p 2222 -o StrictHostKeyChecking=no [email protected] "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@"
337338
```
338339

340+
Here you should also make sure that you've set the permisson of `/app/gitea/gitea` correctly:
341+
342+
```bash
343+
sudo chmod +x /app/gitea/gitea
344+
```
345+
339346
To make the forwarding work, the SSH port of the container (22) needs to be mapped to the host port 2222 in `docker-compose.yml` . Since this port does not need to be exposed to the outside world, it can be mapped to the `localhost` of the host machine:
340347

341348
```bash

models/user_heatmap_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ package models
77
import (
88
"fmt"
99
"testing"
10+
"time"
1011

1112
"code.gitea.io/gitea/models/db"
1213
"code.gitea.io/gitea/modules/json"
14+
"code.gitea.io/gitea/modules/timeutil"
1315

1416
"github.com/stretchr/testify/assert"
1517
)
@@ -39,6 +41,10 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
3941
// Prepare
4042
assert.NoError(t, db.PrepareTestDatabase())
4143

44+
// Mock time
45+
timeutil.Set(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC))
46+
defer timeutil.Unset()
47+
4248
for i, tc := range testCases {
4349
user := db.AssertExistsAndLoadBean(t, &User{ID: tc.userID}).(*User)
4450

modules/timeutil/timestamp.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,24 @@ import (
1313
// TimeStamp defines a timestamp
1414
type TimeStamp int64
1515

16+
// mock is NOT concurrency-safe!!
17+
var mock time.Time
18+
19+
// Set sets the time to a mocked time.Time
20+
func Set(now time.Time) {
21+
mock = now
22+
}
23+
24+
// Unset will unset the mocked time.Time
25+
func Unset() {
26+
mock = time.Time{}
27+
}
28+
1629
// TimeStampNow returns now int64
1730
func TimeStampNow() TimeStamp {
31+
if !mock.IsZero() {
32+
return TimeStamp(mock.Unix())
33+
}
1834
return TimeStamp(time.Now().Unix())
1935
}
2036

options/locale/locale_ja-JP.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,6 +2026,8 @@ diff.file_image_height=高さ
20262026
diff.file_byte_size=サイズ
20272027
diff.file_suppressed=ファイル差分が大きすぎるため省略します
20282028
diff.file_suppressed_line_too_long=長すぎる行があるためファイル差分は表示されません
2029+
diff.too_many_files=変更されたファイルが多すぎるため、一部のファイルは表示されません
2030+
diff.show_more=さらに表示
20292031
diff.generated=generated
20302032
diff.vendored=vendored
20312033
diff.comment.placeholder=コメントを残す

options/locale/locale_zh-CN.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ view_home=访问 %s
228228
search_repos=查找仓库…
229229
filter=其他过滤器
230230
filter_by_team_repositories=按团队仓库筛选
231+
feed_of="%s" 的源
231232

232233
show_archived=已存档
233234
show_both_archived_unarchived=显示已存档和未存档的
@@ -887,6 +888,7 @@ migrate_items_releases=版本发布
887888
migrate_repo=迁移仓库
888889
migrate.clone_address=从 URL 迁移/克隆
889890
migrate.clone_address_desc=现有仓库的 HTTP(s) 或 Git "clone" URL
891+
migrate.github_token_desc=由于 Github API 速率限制,您可以在此处放置一个或多个以逗号分隔的令牌,以加快迁移速度。警告:滥用此功能可能会违反服务提供商的政策并导致帐户被封。
890892
migrate.clone_local_path=或服务器本地路径
891893
migrate.permission_denied=您没有获得导入本地仓库的权限。
892894
migrate.permission_denied_blocked=不允许从被屏蔽的主机导入。
@@ -2026,6 +2028,8 @@ diff.file_image_height=高度
20262028
diff.file_byte_size=大小
20272029
diff.file_suppressed=文件差异内容过多而无法显示
20282030
diff.file_suppressed_line_too_long=文件差异因一行或多行过长而隐藏
2031+
diff.too_many_files=某些文件未显示,因为此 diff 中更改的文件太多
2032+
diff.show_more=显示更多
20292033
diff.generated=自动生成的
20302034
diff.vendored=vendored
20312035
diff.comment.placeholder=留下评论
@@ -2774,6 +2778,8 @@ publish_release=`发布了 <a href="%s/releases/tag/%s"> "%[4]s" </a> 于 <a hre
27742778
review_dismissed=`取消了 <b>%[4]s</b> 对 <a href="%[1]s/pulls/%[2]s">%[3]s#%[2]s</a> 的评审`
27752779
review_dismissed_reason=原因:
27762780
create_branch=创建分支 <a href="%[1]s/src/branch/%[2]s"> %[3]s</a> 于 <a href="%[1]s">%[4]s</a>
2781+
stared_repo=用星号标记了 <a href="%[1]s">%[2]s</a>
2782+
watched_repo=开始关注 <a href="%[1]s">%[2]s</a>
27772783
27782784
[tool]
27792785
ago=%s前

routers/web/user/home.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ func Dashboard(ctx *context.Context) {
7272
ctx.Data["PageIsDashboard"] = true
7373
ctx.Data["PageIsNews"] = true
7474

75+
var uid int64
76+
if ctxUser != nil {
77+
uid = ctxUser.ID
78+
}
79+
7580
ctx.PageData["dashboardRepoList"] = map[string]interface{}{
7681
"searchLimit": setting.UI.User.RepoPagingNum,
82+
"uid": uid,
7783
}
7884

7985
if setting.Service.EnableUserHeatmap {

templates/admin/auth/edit.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</h4>
99
<div class="ui attached segment">
1010
<form class="ui form" action="{{.Link}}" method="post">
11+
{{template "base/disable_form_autofill"}}
1112
{{.CsrfTokenHtml}}
1213
<input type="hidden" name="id" value="{{.Source.ID}}">
1314
<div class="inline field">
@@ -55,7 +56,6 @@
5556
<label for="bind_dn">{{.i18n.Tr "admin.auths.bind_dn"}}</label>
5657
<input id="bind_dn" name="bind_dn" value="{{$cfg.BindDN}}" placeholder="e.g. cn=Search,dc=mydomain,dc=com">
5758
</div>
58-
<input class="fake" type="password">
5959
<div class="field">
6060
<label for="bind_password">{{.i18n.Tr "admin.auths.bind_password"}}</label>
6161
<input id="bind_password" name="bind_password" type="password" value="{{$cfg.BindPassword}}">

templates/admin/auth/new.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</h4>
99
<div class="ui attached segment">
1010
<form class="ui form" action="{{.Link}}" method="post">
11+
{{template "base/disable_form_autofill"}}
1112
{{.CsrfTokenHtml}}
1213
<!-- Types and name -->
1314
<div class="inline required field {{if .Err_Type}}error{{end}}">

templates/admin/auth/source/ldap.tmpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
<label for="bind_dn">{{.i18n.Tr "admin.auths.bind_dn"}}</label>
3131
<input id="bind_dn" name="bind_dn" value="{{.bind_dn}}" placeholder="e.g. cn=Search,dc=mydomain,dc=com">
3232
</div>
33-
<input class="fake" type="password">
3433
<div class="ldap field {{if not (eq .type 2)}}hide{{end}}">
3534
<label for="bind_password">{{.i18n.Tr "admin.auths.bind_password"}}</label>
3635
<input id="bind_password" name="bind_password" type="password" autocomplete="off" value="{{.bind_password}}">

templates/admin/user/edit.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</h4>
99
<div class="ui attached segment">
1010
<form class="ui form" action="{{.Link}}" method="post">
11+
{{template "base/disable_form_autofill"}}
1112
{{.CsrfTokenHtml}}
1213
<div class="field {{if .Err_UserName}}error{{end}}">
1314
<label for="user_name">{{.i18n.Tr "username"}}</label>
@@ -67,7 +68,6 @@
6768
<label for="email">{{.i18n.Tr "email"}}</label>
6869
<input id="email" name="email" type="email" value="{{.User.Email}}" autofocus required>
6970
</div>
70-
<input class="fake" type="password">
7171
<div class="local field {{if .Err_Password}}error{{end}} {{if not (or (.User.IsLocal) (.User.IsOAuth2))}}hide{{end}}">
7272
<label for="password">{{.i18n.Tr "password"}}</label>
7373
<input id="password" name="password" type="password" autocomplete="new-password">

templates/admin/user/new.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</h4>
99
<div class="ui attached segment">
1010
<form class="ui form" action="{{.Link}}" method="post">
11+
{{template "base/disable_form_autofill"}}
1112
{{.CsrfTokenHtml}}
1213
<!-- Types and name -->
1314
<div class="inline required field {{if .Err_LoginType}}error{{end}}">
@@ -61,7 +62,6 @@
6162
<label for="email">{{.i18n.Tr "email"}}</label>
6263
<input id="email" name="email" type="email" value="{{.email}}" required>
6364
</div>
64-
<input class="fake" type="password">
6565
<div class="required local field {{if .Err_Password}}error{{end}} {{if not (eq .login_type "0-0")}}hide{{end}}">
6666
<label for="password">{{.i18n.Tr "password"}}</label>
6767
<input id="password" name="password" type="password" autocomplete="new-password" value="{{.password}}" {{if eq .login_type "0-0"}}required{{end}}>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{{/*
2+
Why we need to disable form autofill:
3+
1. Many pages contain different password inputs for different usages, eg: repo setting, autofill will make a mess.
4+
2. We have `areYouSure` confirm dialog if a user leaves a pages without submit.
5+
Autofill will make the form changed even if the user didn't input anything. Then the user keeps seeing annoying confirm dialog.
6+
7+
In history, Gitea put `<input class="fake" type="password">` in forms to bypass the autofill,
8+
but there were still many forms suffered the autofill problem.
9+
10+
Now we improve it.
11+
12+
Solutions which do NOT work:
13+
1. Adding `autocomplete=off` doesn't help. New Chrome completely ignores it.
14+
2. Use a JavaScript to run in a few seconds later after the page is loaded to process the autofilled inputs, it doesn't work.
15+
Because for security reason, the inputs won't be filled before the user makes an interaction in the page.
16+
So we can not predict the correct time to run the JavaScript code.
17+
18+
Solutions which work:
19+
1. Some hacky methods like: https://github.com/matteobad/detect-autofill
20+
2. This solution: use invisible inputs. Be aware of:
21+
(a) The inputs must be at the beginning of the form, and can not be hidden.
22+
(b) The input for username must have a valid name.
23+
(c) There should be no negative word (eg: fake) in the `name` attribute.
24+
(d) Chrome seems to use a weighted algorithm to choose an input to fill text, so the using "username" as input name is better than using "user".
25+
We make the names of these dummy inputs begin with an underline to indicate it is for special usage,
26+
and these dummy form values won't be used by backend code.
27+
*/}}
28+
<div class="autofill-dummy" aria-hidden="true">
29+
<input type="text" name="_autofill_dummy_username" class="ays-ignore" tabindex="-1">
30+
<input type="password" name="_autofill_dummy_password" class="ays-ignore" tabindex="-1">
31+
</div>

templates/repo/migrate/git.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<div class="ui middle very relaxed page grid">
44
<div class="column">
55
<form class="ui form" action="{{.Link}}" method="post">
6+
{{template "base/disable_form_autofill"}}
67
{{.CsrfTokenHtml}}
78
<h3 class="ui top attached header">
89
{{.i18n.Tr "repo.migrate.migrate" .service.Title}}
@@ -21,7 +22,6 @@
2122
<label for="auth_username">{{.i18n.Tr "username"}}</label>
2223
<input id="auth_username" name="auth_username" value="{{.auth_username}}" {{if not .auth_username}}data-need-clear="true"{{end}}>
2324
</div>
24-
<input class="fake" type="password">
2525
<div class="inline field {{if .Err_Auth}}error{{end}}">
2626
<label for="auth_password">{{.i18n.Tr "password"}}</label>
2727
<input id="auth_password" name="auth_password" type="password" value="{{.auth_password}}">

templates/repo/migrate/onedev.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<div class="ui middle very relaxed page grid">
44
<div class="column">
55
<form class="ui form" action="{{.Link}}" method="post">
6+
{{template "base/disable_form_autofill"}}
67
{{.CsrfTokenHtml}}
78
<h3 class="ui top attached header">
89
{{.i18n.Tr "repo.migrate.migrate" .service.Title}}
@@ -22,7 +23,6 @@
2223
<label for="auth_username">{{.i18n.Tr "username"}}</label>
2324
<input id="auth_username" name="auth_username" value="{{.auth_username}}" {{if not .auth_username}}data-need-clear="true"{{end}}>
2425
</div>
25-
<input class="fake" type="password">
2626
<div class="inline field {{if .Err_Auth}}error{{end}}">
2727
<label for="auth_password">{{.i18n.Tr "password"}}</label>
2828
<input id="auth_password" name="auth_password" type="password" value="{{.auth_password}}">

templates/repo/settings/options.tmpl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</h4>
1010
<div class="ui attached segment">
1111
<form class="ui form" action="{{.Link}}" method="post">
12+
{{template "base/disable_form_autofill"}}
1213
{{.CsrfTokenHtml}}
1314
<input type="hidden" name="action" value="update">
1415
<div class="required field {{if .Err_RepoName}}error{{end}}">
@@ -104,6 +105,7 @@
104105
<tr>
105106
<td colspan="4">
106107
<form class="ui form" method="post">
108+
{{template "base/disable_form_autofill"}}
107109
{{.CsrfTokenHtml}}
108110
<input type="hidden" name="action" value="mirror">
109111
<div class="inline field {{if .Err_EnablePrune}}error{{end}}">
@@ -132,7 +134,6 @@
132134
<label for="mirror_username">{{.i18n.Tr "username"}}</label>
133135
<input id="mirror_username" name="mirror_username" value="{{$address.Username}}" {{if not .mirror_username}}data-need-clear="true"{{end}}>
134136
</div>
135-
<input class="fake" type="password">
136137
<div class="inline field {{if .Err_Auth}}error{{end}}">
137138
<label for="mirror_password">{{.i18n.Tr "password"}}</label>
138139
<input id="mirror_password" name="mirror_password" type="password" placeholder="{{if $address.Password}}{{.i18n.Tr "repo.mirror_password_placeholder"}}{{else}}{{.i18n.Tr "repo.mirror_password_blank_placeholder"}}{{end}}" value="" {{if not .mirror_password}}data-need-clear="true"{{end}} autocomplete="off">
@@ -195,11 +196,12 @@
195196
<tr>
196197
<td colspan="4">
197198
<form class="ui form" method="post">
199+
{{template "base/disable_form_autofill"}}
198200
{{.CsrfTokenHtml}}
199201
<input type="hidden" name="action" value="push-mirror-add">
200202
<div class="field {{if .Err_PushMirrorAddress}}error{{end}}">
201203
<label for="push_mirror_address">{{.i18n.Tr "repo.settings.mirror_settings.push_mirror.remote_url"}}</label>
202-
<input id="push_mirror_address" name="push_mirror_address" value="{{.push_mirror_address}}" autocomplete="off" required>
204+
<input id="push_mirror_address" name="push_mirror_address" value="{{.push_mirror_address}}" required>
203205
<p class="help">{{.i18n.Tr "repo.mirror_address_desc"}}</p>
204206
</div>
205207
<details class="ui optional field" {{if or .Err_PushMirrorAuth .push_mirror_username}}open{{end}}>
@@ -211,7 +213,6 @@
211213
<label for="push_mirror_username">{{.i18n.Tr "username"}}</label>
212214
<input id="push_mirror_username" name="push_mirror_username" value="{{.push_mirror_username}}">
213215
</div>
214-
<input class="fake" type="password">
215216
<div class="inline field {{if .Err_PushMirrorAuth}}error{{end}}">
216217
<label for="push_mirror_password">{{.i18n.Tr "password"}}</label>
217218
<input id="push_mirror_password" name="push_mirror_password" type="password" value="{{.push_mirror_password}}" autocomplete="off">

templates/repo/settings/webhook/gitea.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{if eq .HookType "gitea"}}
22
<p>{{.i18n.Tr "repo.settings.add_webhook_desc" "https://docs.gitea.io/en-us/webhooks/" | Str2html}}</p>
33
<form class="ui form" action="{{.BaseLink}}/gitea/{{or .Webhook.ID "new"}}" method="post">
4+
{{template "base/disable_form_autofill"}}
45
{{.CsrfTokenHtml}}
56
<div class="required field {{if .Err_PayloadURL}}error{{end}}">
67
<label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label>
@@ -30,7 +31,6 @@
3031
</div>
3132
</div>
3233
</div>
33-
<input class="fake" type="password">
3434
<div class="field {{if .Err_Secret}}error{{end}}">
3535
<label for="secret">{{.i18n.Tr "repo.settings.secret"}}</label>
3636
<input id="secret" name="secret" type="password" value="{{.Webhook.Secret}}" autocomplete="off">

templates/repo/settings/webhook/gogs.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{if eq .HookType "gogs"}}
22
<p>{{.i18n.Tr "repo.settings.add_webhook_desc" "https://docs.gitea.io/en-us/webhooks/" | Str2html}}</p>
33
<form class="ui form" action="{{.BaseLink}}/gogs/{{or .Webhook.ID "new"}}" method="post">
4+
{{template "base/disable_form_autofill"}}
45
{{.CsrfTokenHtml}}
56
<div class="required field {{if .Err_PayloadURL}}error{{end}}">
67
<label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label>
@@ -18,7 +19,6 @@
1819
</div>
1920
</div>
2021
</div>
21-
<input class="fake" type="password">
2222
<div class="field {{if .Err_Secret}}error{{end}}">
2323
<label for="secret">{{.i18n.Tr "repo.settings.secret"}}</label>
2424
<input id="secret" name="secret" type="password" value="{{.Webhook.Secret}}" autocomplete="off">

templates/user/dashboard/repolist.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<repo-search
33
:search-limit="searchLimit"
44
:sub-url="subUrl"
5+
:uid="uid"
56
{{if .Team}}
67
:team-id="{{.Team.ID}}"
78
{{end}}
@@ -95,7 +96,7 @@
9596
</div>
9697
</div>
9798
</div>
98-
<div class="ui secondary tiny pointing borderless menu center aligned grid repos-filter">
99+
<div class="ui secondary tiny pointing borderless menu center grid repos-filter">
99100
<a class="item" :class="{active: reposFilter === 'all'}" @click="changeReposFilter('all')">
100101
{{.i18n.Tr "all"}}
101102
<div v-show="reposFilter === 'all'" class="ui circular mini grey label">${repoTypeCount}</div>

templates/user/settings/account.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<div class="ui attached segment">
1010
{{if or (.SignedUser.IsLocal) (.SignedUser.IsOAuth2)}}
1111
<form class="ui form ignore-dirty" action="{{AppSubUrl}}/user/settings/account" method="post">
12+
{{template "base/disable_form_autofill"}}
1213
{{.CsrfTokenHtml}}
1314
{{if .SignedUser.IsPasswordSet}}
1415
<div class="required field {{if .Err_OldPassword}}error{{end}}">
@@ -178,8 +179,8 @@
178179
{{ end }}
179180
</div>
180181
<form class="ui form ignore-dirty" id="delete-form" action="{{AppSubUrl}}/user/settings/account/delete" method="post">
182+
{{template "base/disable_form_autofill"}}
181183
{{.CsrfTokenHtml}}
182-
<input class="fake" type="password">
183184
<div class="required field {{if .Err_Password}}error{{end}}">
184185
<label for="password-confirmation">{{.i18n.Tr "password"}}</label>
185186
<input id="password-confirmation" name="password" type="password" autocomplete="off" required>

web_src/js/components/DashboardRepoList.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ export function initDashboardRepoList() {
362362
return {
363363
searchLimit: dashboardRepoListData.searchLimit || 0,
364364
subUrl: AppSubUrl,
365+
uid: dashboardRepoListData.uid || 0,
365366
};
366367
},
367368
});

0 commit comments

Comments
 (0)