Skip to content

Commit 8324634

Browse files
Merge pull request #31 from go-gitea/main
Fork updates from go-gitea/gitea main
2 parents b2d9e2a + 1856467 commit 8324634

Some content is hidden

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

43 files changed

+386
-365
lines changed

docs/content/doc/advanced/external-renderers.en-us.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,27 @@ Once your configuration changes have been made, restart Gitea to have changes ta
103103
**Note**: Prior to Gitea 1.12 there was a single `markup.sanitiser` section with keys that were redefined for multiple rules, however,
104104
there were significant problems with this method of configuration necessitating configuration through multiple sections.
105105

106+
### Example: HTML
107+
108+
Render HTML files directly:
109+
110+
```ini
111+
[markup.html]
112+
ENABLED = true
113+
FILE_EXTENSIONS = .html,.htm
114+
RENDER_COMMAND = cat
115+
; Input is not a standard input but a file
116+
IS_INPUT_FILE = true
117+
118+
[markup.sanitizer.html.1]
119+
ELEMENT = div
120+
ALLOW_ATTR = class
121+
122+
[markup.sanitizer.html.2]
123+
ELEMENT = a
124+
ALLOW_ATTR = class
125+
```
126+
106127
### Example: Office DOCX
107128

108129
Display Office DOCX files with [`pandoc`](https://pandoc.org/):

models/auth/webauthn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type WebAuthnCredential struct {
4343
Name string
4444
LowerName string `xorm:"unique(s)"`
4545
UserID int64 `xorm:"INDEX unique(s)"`
46-
CredentialID string `xorm:"INDEX"`
46+
CredentialID string `xorm:"INDEX VARCHAR(410)"`
4747
PublicKey []byte
4848
AttestationType string
4949
AAGUID []byte

models/db/context.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ func DeleteByBean(ctx context.Context, bean interface{}) (int64, error) {
148148
return GetEngine(ctx).Delete(bean)
149149
}
150150

151+
// DeleteBeans deletes all given beans, beans should contain delete conditions.
152+
func DeleteBeans(ctx context.Context, beans ...interface{}) (err error) {
153+
e := GetEngine(ctx)
154+
for i := range beans {
155+
if _, err = e.Delete(beans[i]); err != nil {
156+
return err
157+
}
158+
}
159+
return nil
160+
}
161+
151162
// CountByBean counts the number of database records according non-empty fields of the bean as conditions.
152163
func CountByBean(ctx context.Context, bean interface{}) (int64, error) {
153164
return GetEngine(ctx).Count(bean)

models/issue_stopwatch.go

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"code.gitea.io/gitea/models/db"
1313
user_model "code.gitea.io/gitea/models/user"
1414
"code.gitea.io/gitea/modules/timeutil"
15+
"code.gitea.io/gitea/modules/util"
1516
)
1617

1718
// ErrIssueStopwatchNotExist represents an error that stopwatch is not exist
@@ -53,7 +54,7 @@ func (s Stopwatch) Seconds() int64 {
5354

5455
// Duration returns a human-readable duration string based on local server time
5556
func (s Stopwatch) Duration() string {
56-
return SecToTime(s.Seconds())
57+
return util.SecToTime(s.Seconds())
5758
}
5859

5960
func getStopwatch(ctx context.Context, userID, issueID int64) (sw *Stopwatch, exists bool, err error) {
@@ -164,7 +165,7 @@ func FinishIssueStopwatch(ctx context.Context, user *user_model.User, issue *Iss
164165
Doer: user,
165166
Issue: issue,
166167
Repo: issue.Repo,
167-
Content: SecToTime(timediff),
168+
Content: util.SecToTime(timediff),
168169
Type: CommentTypeStopTracking,
169170
TimeID: tt.ID,
170171
}); err != nil {
@@ -263,32 +264,3 @@ func cancelStopwatch(ctx context.Context, user *user_model.User, issue *Issue) e
263264
}
264265
return nil
265266
}
266-
267-
// SecToTime converts an amount of seconds to a human-readable string (example: 66s -> 1min 6s)
268-
func SecToTime(duration int64) string {
269-
seconds := duration % 60
270-
minutes := (duration / (60)) % 60
271-
hours := duration / (60 * 60)
272-
273-
var hrs string
274-
275-
if hours > 0 {
276-
hrs = fmt.Sprintf("%dh", hours)
277-
}
278-
if minutes > 0 {
279-
if hours == 0 {
280-
hrs = fmt.Sprintf("%dmin", minutes)
281-
} else {
282-
hrs = fmt.Sprintf("%s %dmin", hrs, minutes)
283-
}
284-
}
285-
if seconds > 0 {
286-
if hours == 0 && minutes == 0 {
287-
hrs = fmt.Sprintf("%ds", seconds)
288-
} else {
289-
hrs = fmt.Sprintf("%s %ds", hrs, seconds)
290-
}
291-
}
292-
293-
return hrs
294-
}

models/issue_tracked_time.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/models/db"
1212
user_model "code.gitea.io/gitea/models/user"
1313
"code.gitea.io/gitea/modules/setting"
14+
"code.gitea.io/gitea/modules/util"
1415

1516
"xorm.io/builder"
1617
)
@@ -177,7 +178,7 @@ func AddTime(user *user_model.User, issue *Issue, amount int64, created time.Tim
177178
Issue: issue,
178179
Repo: issue.Repo,
179180
Doer: user,
180-
Content: SecToTime(amount),
181+
Content: util.SecToTime(amount),
181182
Type: CommentTypeAddTimeManual,
182183
TimeID: t.ID,
183184
}); err != nil {
@@ -226,7 +227,7 @@ func TotalTimes(options *FindTrackedTimesOptions) (map[*user_model.User]string,
226227
}
227228
return nil, err
228229
}
229-
totalTimes[user] = SecToTime(total)
230+
totalTimes[user] = util.SecToTime(total)
230231
}
231232
return totalTimes, nil
232233
}
@@ -260,7 +261,7 @@ func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error {
260261
Issue: issue,
261262
Repo: issue.Repo,
262263
Doer: user,
263-
Content: "- " + SecToTime(removedTime),
264+
Content: "- " + util.SecToTime(removedTime),
264265
Type: CommentTypeDeleteTimeManual,
265266
}); err != nil {
266267
return err
@@ -289,7 +290,7 @@ func DeleteTime(t *TrackedTime) error {
289290
Issue: t.Issue,
290291
Repo: t.Issue.Repo,
291292
Doer: t.User,
292-
Content: "- " + SecToTime(t.Time),
293+
Content: "- " + util.SecToTime(t.Time),
293294
Type: CommentTypeDeleteTimeManual,
294295
}); err != nil {
295296
return err

models/issue_tracked_time_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestAddTime(t *testing.T) {
3434
assert.Equal(t, int64(3661), tt.Time)
3535

3636
comment := unittest.AssertExistsAndLoadBean(t, &Comment{Type: CommentTypeAddTimeManual, PosterID: 3, IssueID: 1}).(*Comment)
37-
assert.Equal(t, comment.Content, "1h 1min 1s")
37+
assert.Equal(t, comment.Content, "1h 1m 1s")
3838
}
3939

4040
func TestGetTrackedTimes(t *testing.T) {
@@ -86,15 +86,15 @@ func TestTotalTimes(t *testing.T) {
8686
assert.Len(t, total, 1)
8787
for user, time := range total {
8888
assert.Equal(t, int64(1), user.ID)
89-
assert.Equal(t, "6min 40s", time)
89+
assert.Equal(t, "6m 40s", time)
9090
}
9191

9292
total, err = TotalTimes(&FindTrackedTimesOptions{IssueID: 2})
9393
assert.NoError(t, err)
9494
assert.Len(t, total, 2)
9595
for user, time := range total {
9696
if user.ID == 2 {
97-
assert.Equal(t, "1h 1min 2s", time)
97+
assert.Equal(t, "1h 1m 2s", time)
9898
} else if user.ID == 1 {
9999
assert.Equal(t, "20s", time)
100100
} else {
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
-
55
id: 2
66
credential_id: "TVHE44TOH7DF7V48SEAIT3EMMJ7TGBOQ289E5AQB34S98LFCUFJ7U2NAVI8RJG6K2F4TC8AQ8KBNO7AGEOQOL9NE43GR63HTEHJSLOG="
7+
-
8+
id: 3
9+
credential_id: "TVHE44TOH7DF7V48SEAIT3EMMJ7TGBOQ289E5AQB34S98LFCUFJ7U2NAVI8RJG6K2F4TC8AQ8KBNO7AGEOQOL9NE43GR63HTEHJSLOG="
710
-
811
id: 4
9-
credential_id: "THIS SHOULD NOT CHAGNGE"
12+
credential_id: "TVHE44TOH7DF7V48SEAIT3EMMJ7TGBOQ289E5AQB34S98LFCUFJ7U2NAVI8RJG6K2F4TC8AQ8KBNO7AGEOQOL9NE43GR63HTEHJSLOG="

models/migrations/fixtures/Test_increaseCredentialIDTo410/webauthn_credential.yml renamed to models/migrations/fixtures/Test_remigrateU2FCredentials/webauthn_credential.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
lower_name: "u2fkey-wrong-user-id"
2424
name: "u2fkey-wrong-user-id"
2525
user_id: 1
26-
credential_id: "THIS SHOULD NOT CHAGNGE"
26+
credential_id: "THIS SHOULD CHANGE"
2727
public_key: 0x040d0967a2cad045011631187576492a0beb5b377954b4f694c5afc8bdf25270f87f09a9ab6ce9c282f447ba71b2f2bae2105b32b847e0704f310f48644e3eddf2
2828
attestation_type: 'fido-u2f'
2929
sign_count: 1

models/migrations/migrations.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,13 @@ var migrations = []Migration{
367367
// v206 -> v207
368368
NewMigration("Add authorize column to team_unit table", addAuthorizeColForTeamUnit),
369369
// v207 -> v208
370-
NewMigration("Add webauthn table and migrate u2f data to webauthn", addWebAuthnCred),
370+
NewMigration("Add webauthn table and migrate u2f data to webauthn - NO-OPED", addWebAuthnCred),
371371
// v208 -> v209
372-
NewMigration("Use base32.HexEncoding instead of base64 encoding for cred ID as it is case insensitive", useBase32HexForCredIDInWebAuthnCredential),
372+
NewMigration("Use base32.HexEncoding instead of base64 encoding for cred ID as it is case insensitive - NO-OPED", useBase32HexForCredIDInWebAuthnCredential),
373373
// v209 -> v210
374-
NewMigration("Increase WebAuthentication CredentialID size to 410", increaseCredentialIDTo410),
374+
NewMigration("Increase WebAuthentication CredentialID size to 410 - NO-OPED", increaseCredentialIDTo410),
375+
// v210 -> v211
376+
NewMigration("v208 was completely broken - remigrate", remigrateU2FCredentials),
375377
}
376378

377379
// GetCurrentDBVersion returns the current db version

0 commit comments

Comments
 (0)