Skip to content

Commit e100c4e

Browse files
lunnylyricwulf
authored andcommitted
Allow deleting comment with content via API like web did (go-gitea#35346)
Fix go-gitea#35296
1 parent c7b99c8 commit e100c4e

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

routers/api/v1/repo/issue_comment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,8 @@ func deleteIssueComment(ctx *context.APIContext) {
721721
if !ctx.IsSigned || (ctx.Doer.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
722722
ctx.Status(http.StatusForbidden)
723723
return
724-
} else if comment.Type != issues_model.CommentTypeComment {
725-
ctx.Status(http.StatusNoContent)
724+
} else if !comment.Type.HasContentSupport() {
725+
ctx.Status(http.StatusBadRequest)
726726
return
727727
}
728728

services/asymkey/sign.go

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,32 @@ func signingModeFromStrings(modeStrings []string) []signingMode {
6969
return returnable
7070
}
7171

72+
func userHasPubkeys(ctx context.Context, u *user_model.User) (bool, error) {
73+
gpgKeys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
74+
OwnerID: u.ID,
75+
includeSubKeys: true,
76+
})
77+
if err != nil {
78+
return nil, err
79+
}
80+
if len(gpgKeys) > 0 {
81+
return true, nil
82+
}
83+
84+
sshKeys, err := db.Find[asymkey_model.PublicKey](ctx, asymkey_model.FindPublicKeyOptions{
85+
OwnerID: u.ID,
86+
NotKeytype: asymkey_model.KeyTypePrincipal,
87+
})
88+
if err != nil {
89+
return nil, err
90+
}
91+
if len(sshKeys) > 0 {
92+
return true, nil
93+
}
94+
95+
return false, nil
96+
}
97+
7298
// ErrWontSign explains the first reason why a commit would not be signed
7399
// There may be other reasons - this is just the first reason found
74100
type ErrWontSign struct {
@@ -170,14 +196,11 @@ Loop:
170196
case always:
171197
break Loop
172198
case pubkey:
173-
keys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
174-
OwnerID: u.ID,
175-
IncludeSubKeys: true,
176-
})
199+
hasKeys, err := userHasPubkeys(ctx, u)
177200
if err != nil {
178201
return false, nil, nil, err
179202
}
180-
if len(keys) == 0 {
203+
if !hasKeys {
181204
return false, nil, nil, &ErrWontSign{pubkey}
182205
}
183206
case twofa:
@@ -210,14 +233,11 @@ Loop:
210233
case always:
211234
break Loop
212235
case pubkey:
213-
keys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
214-
OwnerID: u.ID,
215-
IncludeSubKeys: true,
216-
})
236+
hasKeys, err := userHasPubkeys(ctx, u)
217237
if err != nil {
218238
return false, nil, nil, err
219239
}
220-
if len(keys) == 0 {
240+
if !hasKeys {
221241
return false, nil, nil, &ErrWontSign{pubkey}
222242
}
223243
case twofa:
@@ -266,14 +286,11 @@ Loop:
266286
case always:
267287
break Loop
268288
case pubkey:
269-
keys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
270-
OwnerID: u.ID,
271-
IncludeSubKeys: true,
272-
})
289+
hasKeys, err := userHasPubkeys(ctx, u)
273290
if err != nil {
274291
return false, nil, nil, err
275292
}
276-
if len(keys) == 0 {
293+
if !hasKeys {
277294
return false, nil, nil, &ErrWontSign{pubkey}
278295
}
279296
case twofa:
@@ -337,14 +354,11 @@ Loop:
337354
case always:
338355
break Loop
339356
case pubkey:
340-
keys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
341-
OwnerID: u.ID,
342-
IncludeSubKeys: true,
343-
})
357+
hasKeys, err := userHasPubkeys(ctx, u)
344358
if err != nil {
345359
return false, nil, nil, err
346360
}
347-
if len(keys) == 0 {
361+
if !hasKeys {
348362
return false, nil, nil, &ErrWontSign{pubkey}
349363
}
350364
case twofa:

0 commit comments

Comments
 (0)