Skip to content

Commit 710f67c

Browse files
committed
Merge remote-tracking branch 'giteaoffical/main'
* giteaoffical/main: Add login name and source id for admin user searching API (go-gitea#23376) Fix missed migration in go-gitea#22235 (go-gitea#23482) Disable sending email after push a commit to a closed PR (go-gitea#23462)
2 parents a4a7dce + 6f9cc61 commit 710f67c

File tree

8 files changed

+67
-9
lines changed

8 files changed

+67
-9
lines changed

models/fixtures/project.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-
22
id: 1
33
title: First project
4+
owner_id: 0
45
repo_id: 1
56
is_closed: false
67
creator_id: 2
@@ -10,6 +11,7 @@
1011
-
1112
id: 2
1213
title: second project
14+
owner_id: 0
1315
repo_id: 3
1416
is_closed: false
1517
creator_id: 3
@@ -19,6 +21,7 @@
1921
-
2022
id: 3
2123
title: project on repo with disabled project
24+
owner_id: 0
2225
repo_id: 4
2326
is_closed: true
2427
creator_id: 5
@@ -29,6 +32,7 @@
2932
id: 4
3033
title: project on user2
3134
owner_id: 2
35+
repo_id: 0
3236
is_closed: false
3337
creator_id: 2
3438
board_type: 1

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ var migrations = []Migration{
469469
NewMigration("Add NeedApproval to actions tables", v1_20.AddNeedApprovalToActionRun),
470470
// v245 -> v246
471471
NewMigration("Rename Webhook org_id to owner_id", v1_20.RenameWebhookOrgToOwner),
472+
// v246 -> v247
473+
NewMigration("Add missed column owner_id for project table", v1_20.AddNewColumnForProject),
472474
}
473475

474476
// GetCurrentDBVersion returns the current db version

models/migrations/v1_20/v246.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_20 //nolint
5+
6+
import (
7+
"xorm.io/xorm"
8+
)
9+
10+
func AddNewColumnForProject(x *xorm.Engine) error {
11+
type Project struct {
12+
OwnerID int64 `xorm:"INDEX"`
13+
}
14+
15+
return x.Sync(new(Project))
16+
}

models/user/search.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type SearchUserOptions struct {
2222
Keyword string
2323
Type UserType
2424
UID int64
25+
LoginName string // this option should be used only for admin user
26+
SourceID int64 // this option should be used only for admin user
2527
OrderBy db.SearchOrderBy
2628
Visible []structs.VisibleType
2729
Actor *User // The user doing the search
@@ -62,6 +64,13 @@ func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session {
6264
cond = cond.And(builder.Eq{"id": opts.UID})
6365
}
6466

67+
if opts.SourceID > 0 {
68+
cond = cond.And(builder.Eq{"login_source": opts.SourceID})
69+
}
70+
if opts.LoginName != "" {
71+
cond = cond.And(builder.Eq{"login_name": opts.LoginName})
72+
}
73+
6574
if !opts.IsActive.IsNone() {
6675
cond = cond.And(builder.Eq{"is_active": opts.IsActive.IsTrue()})
6776
}

routers/api/v1/admin/user.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,14 +417,23 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
417417
ctx.Status(http.StatusNoContent)
418418
}
419419

420-
// GetAllUsers API for getting information of all the users
421-
func GetAllUsers(ctx *context.APIContext) {
422-
// swagger:operation GET /admin/users admin adminGetAllUsers
420+
// SearchUsers API for getting information of the users according the filter conditions
421+
func SearchUsers(ctx *context.APIContext) {
422+
// swagger:operation GET /admin/users admin adminSearchUsers
423423
// ---
424-
// summary: List all users
424+
// summary: Search users according filter conditions
425425
// produces:
426426
// - application/json
427427
// parameters:
428+
// - name: source_id
429+
// in: query
430+
// description: ID of the user's login source to search for
431+
// type: integer
432+
// format: int64
433+
// - name: login_name
434+
// in: query
435+
// description: user's login name to search for
436+
// type: string
428437
// - name: page
429438
// in: query
430439
// description: page number of results to return (1-based)
@@ -444,11 +453,13 @@ func GetAllUsers(ctx *context.APIContext) {
444453
users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
445454
Actor: ctx.Doer,
446455
Type: user_model.UserTypeIndividual,
456+
LoginName: ctx.FormTrim("login_name"),
457+
SourceID: ctx.FormInt64("source_id"),
447458
OrderBy: db.SearchOrderByAlphabetically,
448459
ListOptions: listOptions,
449460
})
450461
if err != nil {
451-
ctx.Error(http.StatusInternalServerError, "GetAllUsers", err)
462+
ctx.Error(http.StatusInternalServerError, "SearchUsers", err)
452463
return
453464
}
454465

routers/api/v1/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ func Routes(ctx gocontext.Context) *web.Route {
12451245
})
12461246
m.Get("/orgs", admin.GetAllOrgs)
12471247
m.Group("/users", func() {
1248-
m.Get("", admin.GetAllUsers)
1248+
m.Get("", admin.SearchUsers)
12491249
m.Post("", bind(api.CreateUserOption{}), admin.CreateUser)
12501250
m.Group("/{username}", func() {
12511251
m.Combo("").Patch(bind(api.EditUserOption{}), admin.EditUser).

services/pull/pull.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,12 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
274274
continue
275275
}
276276

277+
// If the PR is closed, someone still push some commits to the PR,
278+
// 1. We will insert comments of commits, but hidden until the PR is reopened.
279+
// 2. We won't send any notification.
277280
AddToTaskQueue(pr)
278281
comment, err := CreatePushPullComment(ctx, doer, pr, oldCommitID, newCommitID)
279-
if err == nil && comment != nil {
282+
if err == nil && comment != nil && !pr.Issue.IsClosed {
280283
notification.NotifyPullRequestPushCommits(ctx, doer, pr, comment)
281284
}
282285
}

templates/swagger/v1_json.tmpl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,22 @@
488488
"tags": [
489489
"admin"
490490
],
491-
"summary": "List all users",
492-
"operationId": "adminGetAllUsers",
491+
"summary": "Search users according filter conditions",
492+
"operationId": "adminSearchUsers",
493493
"parameters": [
494+
{
495+
"type": "integer",
496+
"format": "int64",
497+
"description": "ID of the user's login source to search for",
498+
"name": "source_id",
499+
"in": "query"
500+
},
501+
{
502+
"type": "string",
503+
"description": "user's login name to search for",
504+
"name": "login_name",
505+
"in": "query"
506+
},
494507
{
495508
"type": "integer",
496509
"description": "page number of results to return (1-based)",

0 commit comments

Comments
 (0)