Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaoffical/main'
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
zjjhot committed Mar 15, 2023
2 parents a4a7dce + 6f9cc61 commit 710f67c
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 9 deletions.
4 changes: 4 additions & 0 deletions models/fixtures/project.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-
id: 1
title: First project
owner_id: 0
repo_id: 1
is_closed: false
creator_id: 2
Expand All @@ -10,6 +11,7 @@
-
id: 2
title: second project
owner_id: 0
repo_id: 3
is_closed: false
creator_id: 3
Expand All @@ -19,6 +21,7 @@
-
id: 3
title: project on repo with disabled project
owner_id: 0
repo_id: 4
is_closed: true
creator_id: 5
Expand All @@ -29,6 +32,7 @@
id: 4
title: project on user2
owner_id: 2
repo_id: 0
is_closed: false
creator_id: 2
board_type: 1
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ var migrations = []Migration{
NewMigration("Add NeedApproval to actions tables", v1_20.AddNeedApprovalToActionRun),
// v245 -> v246
NewMigration("Rename Webhook org_id to owner_id", v1_20.RenameWebhookOrgToOwner),
// v246 -> v247
NewMigration("Add missed column owner_id for project table", v1_20.AddNewColumnForProject),
}

// GetCurrentDBVersion returns the current db version
Expand Down
16 changes: 16 additions & 0 deletions models/migrations/v1_20/v246.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_20 //nolint

import (
"xorm.io/xorm"
)

func AddNewColumnForProject(x *xorm.Engine) error {
type Project struct {
OwnerID int64 `xorm:"INDEX"`
}

return x.Sync(new(Project))
}
9 changes: 9 additions & 0 deletions models/user/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type SearchUserOptions struct {
Keyword string
Type UserType
UID int64
LoginName string // this option should be used only for admin user
SourceID int64 // this option should be used only for admin user
OrderBy db.SearchOrderBy
Visible []structs.VisibleType
Actor *User // The user doing the search
Expand Down Expand Up @@ -62,6 +64,13 @@ func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session {
cond = cond.And(builder.Eq{"id": opts.UID})
}

if opts.SourceID > 0 {
cond = cond.And(builder.Eq{"login_source": opts.SourceID})
}
if opts.LoginName != "" {
cond = cond.And(builder.Eq{"login_name": opts.LoginName})
}

if !opts.IsActive.IsNone() {
cond = cond.And(builder.Eq{"is_active": opts.IsActive.IsTrue()})
}
Expand Down
21 changes: 16 additions & 5 deletions routers/api/v1/admin/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,23 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
ctx.Status(http.StatusNoContent)
}

// GetAllUsers API for getting information of all the users
func GetAllUsers(ctx *context.APIContext) {
// swagger:operation GET /admin/users admin adminGetAllUsers
// SearchUsers API for getting information of the users according the filter conditions
func SearchUsers(ctx *context.APIContext) {
// swagger:operation GET /admin/users admin adminSearchUsers
// ---
// summary: List all users
// summary: Search users according filter conditions
// produces:
// - application/json
// parameters:
// - name: source_id
// in: query
// description: ID of the user's login source to search for
// type: integer
// format: int64
// - name: login_name
// in: query
// description: user's login name to search for
// type: string
// - name: page
// in: query
// description: page number of results to return (1-based)
Expand All @@ -444,11 +453,13 @@ func GetAllUsers(ctx *context.APIContext) {
users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
Actor: ctx.Doer,
Type: user_model.UserTypeIndividual,
LoginName: ctx.FormTrim("login_name"),
SourceID: ctx.FormInt64("source_id"),
OrderBy: db.SearchOrderByAlphabetically,
ListOptions: listOptions,
})
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetAllUsers", err)
ctx.Error(http.StatusInternalServerError, "SearchUsers", err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ func Routes(ctx gocontext.Context) *web.Route {
})
m.Get("/orgs", admin.GetAllOrgs)
m.Group("/users", func() {
m.Get("", admin.GetAllUsers)
m.Get("", admin.SearchUsers)
m.Post("", bind(api.CreateUserOption{}), admin.CreateUser)
m.Group("/{username}", func() {
m.Combo("").Patch(bind(api.EditUserOption{}), admin.EditUser).
Expand Down
5 changes: 4 additions & 1 deletion services/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,12 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
continue
}

// If the PR is closed, someone still push some commits to the PR,
// 1. We will insert comments of commits, but hidden until the PR is reopened.
// 2. We won't send any notification.
AddToTaskQueue(pr)
comment, err := CreatePushPullComment(ctx, doer, pr, oldCommitID, newCommitID)
if err == nil && comment != nil {
if err == nil && comment != nil && !pr.Issue.IsClosed {
notification.NotifyPullRequestPushCommits(ctx, doer, pr, comment)
}
}
Expand Down
17 changes: 15 additions & 2 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,22 @@
"tags": [
"admin"
],
"summary": "List all users",
"operationId": "adminGetAllUsers",
"summary": "Search users according filter conditions",
"operationId": "adminSearchUsers",
"parameters": [
{
"type": "integer",
"format": "int64",
"description": "ID of the user's login source to search for",
"name": "source_id",
"in": "query"
},
{
"type": "string",
"description": "user's login name to search for",
"name": "login_name",
"in": "query"
},
{
"type": "integer",
"description": "page number of results to return (1-based)",
Expand Down

0 comments on commit 710f67c

Please sign in to comment.