Skip to content

Commit 68d8731

Browse files
ashimokawafnetX
authored andcommitted
CB/feat: Simple rate limiting for issues
1 parent cbd1f3c commit 68d8731

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

models/issue.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,13 @@ type NewIssueOptions struct {
928928

929929
func newIssue(ctx context.Context, doer *user_model.User, opts NewIssueOptions) (err error) {
930930
e := db.GetEngine(ctx)
931+
// codeberg specific
932+
var id int64
933+
has, err := e.Table("issue").Where("poster_id = ?", doer.ID).And("unix_timestamp()-created_unix<30").Limit(1).Get(&id)
934+
if has == true {
935+
return fmt.Errorf("NewIssue: Unknown error")
936+
}
937+
931938
opts.Issue.Title = strings.TrimSpace(opts.Issue.Title)
932939

933940
if opts.Issue.MilestoneID > 0 {

models/issue_comment.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,15 @@ func (c *Comment) LoadPushCommits() (err error) {
761761

762762
func createComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment, err error) {
763763
e := db.GetEngine(ctx)
764+
// codeberg-specific
765+
if opts.Type == CommentTypeComment {
766+
var id int64
767+
has, _ := e.Table("comment").Where("poster_id = ?", opts.Doer.ID).And("unix_timestamp()-created_unix<10").And("type=0").Limit(1).Get(&id)
768+
if has == true {
769+
return nil, fmt.Errorf("NewComment: Unknown error")
770+
}
771+
}
772+
764773
var LabelID int64
765774
if opts.Label != nil {
766775
LabelID = opts.Label.ID

0 commit comments

Comments
 (0)