Skip to content

Commit 8f9c825

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated translations via Crowdin Refactor deletion (go-gitea#28610) Refactor CORS handler (go-gitea#28587)
2 parents a548fe7 + ff7383e commit 8f9c825

Some content is hidden

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

67 files changed

+228
-292
lines changed

custom/conf/app.example.ini

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,15 +1158,9 @@ LEVEL = Info
11581158
;; enable cors headers (disabled by default)
11591159
;ENABLED = false
11601160
;;
1161-
;; scheme of allowed requests
1162-
;SCHEME = http
1163-
;;
1164-
;; list of requesting domains that are allowed
1161+
;; list of requesting origins that are allowed, eg: "https://*.example.com"
11651162
;ALLOW_DOMAIN = *
11661163
;;
1167-
;; allow subdomains of headers listed above to request
1168-
;ALLOW_SUBDOMAIN = false
1169-
;;
11701164
;; list of methods allowed to request
11711165
;METHODS = GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS
11721166
;;

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a
196196
## CORS (`cors`)
197197

198198
- `ENABLED`: **false**: enable cors headers (disabled by default)
199-
- `SCHEME`: **http**: scheme of allowed requests
200-
- `ALLOW_DOMAIN`: **\***: list of requesting domains that are allowed
201-
- `ALLOW_SUBDOMAIN`: **false**: allow subdomains of headers listed above to request
199+
- `ALLOW_DOMAIN`: **\***: list of requesting origins that are allowed, eg: "https://*.example.com"
202200
- `METHODS`: **GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS**: list of methods allowed to request
203201
- `MAX_AGE`: **10m**: max time to cache response
204202
- `ALLOW_CREDENTIALS`: **false**: allow request with credentials

docs/content/administration/config-cheat-sheet.zh-cn.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,7 @@ menu:
195195
## 跨域 (`cors`)
196196

197197
- `ENABLED`: **false**: 启用 CORS 头部(默认禁用)
198-
- `SCHEME`: **http**: 允许请求的协议
199198
- `ALLOW_DOMAIN`: **\***: 允许请求的域名列表
200-
- `ALLOW_SUBDOMAIN`: **false**: 允许上述列出的头部的子域名发出请求。
201199
- `METHODS`: **GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS**: 允许发起的请求方式列表
202200
- `MAX_AGE`: **10m**: 缓存响应的最大时间
203201
- `ALLOW_CREDENTIALS`: **false**: 允许带有凭据的请求

models/actions/artifact.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,6 @@ func getArtifactByNameAndPath(ctx context.Context, runID int64, name, fpath stri
9090
return &art, nil
9191
}
9292

93-
// GetArtifactByID returns an artifact by id
94-
func GetArtifactByID(ctx context.Context, id int64) (*ActionArtifact, error) {
95-
var art ActionArtifact
96-
has, err := db.GetEngine(ctx).ID(id).Get(&art)
97-
if err != nil {
98-
return nil, err
99-
} else if !has {
100-
return nil, util.ErrNotExist
101-
}
102-
103-
return &art, nil
104-
}
105-
10693
// UpdateArtifactByID updates an artifact by id
10794
func UpdateArtifactByID(ctx context.Context, id int64, art *ActionArtifact) error {
10895
art.ID = id

models/actions/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func DeleteRunner(ctx context.Context, id int64) error {
254254
return err
255255
}
256256

257-
_, err := db.GetEngine(ctx).Delete(&ActionRunner{ID: id})
257+
_, err := db.DeleteByID[ActionRunner](ctx, id)
258258
return err
259259
}
260260

models/asymkey/ssh_key.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,6 @@ func UpdatePublicKeyUpdated(ctx context.Context, id int64) error {
227227
return nil
228228
}
229229

230-
// DeletePublicKeys does the actual key deletion but does not update authorized_keys file.
231-
func DeletePublicKeys(ctx context.Context, keyIDs ...int64) error {
232-
if len(keyIDs) == 0 {
233-
return nil
234-
}
235-
236-
_, err := db.GetEngine(ctx).In("id", keyIDs).Delete(new(PublicKey))
237-
return err
238-
}
239-
240230
// PublicKeysAreExternallyManaged returns whether the provided KeyID represents an externally managed Key
241231
func PublicKeysAreExternallyManaged(ctx context.Context, keys []*PublicKey) ([]bool, error) {
242232
sources := make([]*auth.Source, 0, 5)
@@ -322,8 +312,8 @@ func deleteKeysMarkedForDeletion(ctx context.Context, keys []string) (bool, erro
322312
log.Error("SearchPublicKeyByContent: %v", err)
323313
continue
324314
}
325-
if err = DeletePublicKeys(ctx, key.ID); err != nil {
326-
log.Error("deletePublicKeys: %v", err)
315+
if _, err = db.DeleteByID[PublicKey](ctx, key.ID); err != nil {
316+
log.Error("DeleteByID[PublicKey]: %v", err)
327317
continue
328318
}
329319
sshKeysNeedUpdate = true

models/db/context.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func Exec(ctx context.Context, sqlAndArgs ...any) (sql.Result, error) {
175175

176176
func Get[T any](ctx context.Context, cond builder.Cond) (object *T, exist bool, err error) {
177177
if !cond.IsValid() {
178-
return nil, false, ErrConditionRequired{}
178+
panic("cond is invalid in db.Get(ctx, cond). This should not be possible.")
179179
}
180180

181181
var bean T
@@ -201,7 +201,7 @@ func GetByID[T any](ctx context.Context, id int64) (object *T, exist bool, err e
201201

202202
func Exist[T any](ctx context.Context, cond builder.Cond) (bool, error) {
203203
if !cond.IsValid() {
204-
return false, ErrConditionRequired{}
204+
panic("cond is invalid in db.Exist(ctx, cond). This should not be possible.")
205205
}
206206

207207
var bean T
@@ -213,16 +213,36 @@ func ExistByID[T any](ctx context.Context, id int64) (bool, error) {
213213
return GetEngine(ctx).ID(id).NoAutoCondition().Exist(&bean)
214214
}
215215

216+
// DeleteByID deletes the given bean with the given ID
217+
func DeleteByID[T any](ctx context.Context, id int64) (int64, error) {
218+
var bean T
219+
return GetEngine(ctx).ID(id).NoAutoCondition().NoAutoTime().Delete(&bean)
220+
}
221+
222+
func DeleteByIDs[T any](ctx context.Context, ids ...int64) error {
223+
if len(ids) == 0 {
224+
return nil
225+
}
226+
227+
var bean T
228+
_, err := GetEngine(ctx).In("id", ids).NoAutoCondition().NoAutoTime().Delete(&bean)
229+
return err
230+
}
231+
232+
func Delete[T any](ctx context.Context, opts FindOptions) (int64, error) {
233+
if opts == nil || !opts.ToConds().IsValid() {
234+
panic("opts are empty or invalid in db.Delete(ctx, opts). This should not be possible.")
235+
}
236+
237+
var bean T
238+
return GetEngine(ctx).Where(opts.ToConds()).NoAutoCondition().NoAutoTime().Delete(&bean)
239+
}
240+
216241
// DeleteByBean deletes all records according non-empty fields of the bean as conditions.
217242
func DeleteByBean(ctx context.Context, bean any) (int64, error) {
218243
return GetEngine(ctx).Delete(bean)
219244
}
220245

221-
// DeleteByID deletes the given bean with the given ID
222-
func DeleteByID(ctx context.Context, id int64, bean any) (int64, error) {
223-
return GetEngine(ctx).ID(id).NoAutoCondition().NoAutoTime().Delete(bean)
224-
}
225-
226246
// FindIDs finds the IDs for the given table name satisfying the given condition
227247
// By passing a different value than "id" for "idCol", you can query for foreign IDs, i.e. the repo IDs which satisfy the condition
228248
func FindIDs(ctx context.Context, tableName, idCol string, cond builder.Cond) ([]int64, error) {

models/db/error.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,3 @@ func (err ErrNotExist) Error() string {
7272
func (err ErrNotExist) Unwrap() error {
7373
return util.ErrNotExist
7474
}
75-
76-
// ErrConditionRequired represents an error which require condition.
77-
type ErrConditionRequired struct{}
78-
79-
// IsErrConditionRequired checks if an error is an ErrConditionRequired
80-
func IsErrConditionRequired(err error) bool {
81-
_, ok := err.(ErrConditionRequired)
82-
return ok
83-
}
84-
85-
func (err ErrConditionRequired) Error() string {
86-
return "condition is required"
87-
}
88-
89-
// Unwrap unwraps this as a ErrNotExist err
90-
func (err ErrConditionRequired) Unwrap() error {
91-
return util.ErrInvalidArgument
92-
}

models/issues/issue_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ func TestIssue_InsertIssue(t *testing.T) {
249249

250250
// there are 5 issues and max index is 5 on repository 1, so this one should 6
251251
issue := testInsertIssue(t, "my issue1", "special issue's comments?", 6)
252-
_, err := db.GetEngine(db.DefaultContext).ID(issue.ID).Delete(new(issues_model.Issue))
252+
_, err := db.DeleteByID[issues_model.Issue](db.DefaultContext, issue.ID)
253253
assert.NoError(t, err)
254254

255255
issue = testInsertIssue(t, `my issue2, this is my son's love \n \r \ `, "special issue's '' comments?", 7)
256-
_, err = db.GetEngine(db.DefaultContext).ID(issue.ID).Delete(new(issues_model.Issue))
256+
_, err = db.DeleteByID[issues_model.Issue](db.DefaultContext, issue.ID)
257257
assert.NoError(t, err)
258258
}
259259

models/issues/label.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func DeleteLabel(ctx context.Context, id, labelID int64) error {
256256
return nil
257257
}
258258

259-
if _, err = sess.ID(labelID).Delete(new(Label)); err != nil {
259+
if _, err = db.DeleteByID[Label](ctx, labelID); err != nil {
260260
return err
261261
} else if _, err = sess.
262262
Where("label_id = ?", labelID).

0 commit comments

Comments
 (0)