Skip to content

Commit 7ebf907

Browse files
authored
Merge branch 'main' into fix-dropzone-image
2 parents cd9febc + 620f196 commit 7ebf907

File tree

28 files changed

+282
-150
lines changed

28 files changed

+282
-150
lines changed

cmd/admin_auth_ldap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func (a *authService) addLdapSimpleAuth(c *cli.Context) error {
386386
return a.createAuthSource(ctx, authSource)
387387
}
388388

389-
// updateLdapBindDn updates a new LDAP (simple auth) authentication source.
389+
// updateLdapSimpleAuth updates a new LDAP (simple auth) authentication source.
390390
func (a *authService) updateLdapSimpleAuth(c *cli.Context) error {
391391
ctx, cancel := installSignals()
392392
defer cancel()

contrib/backport/backport.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ func main() {
6464
Value: "",
6565
Usage: "Forked user name on Github",
6666
},
67+
&cli.StringFlag{
68+
Name: "gh-access-token",
69+
Value: "",
70+
Usage: "Access token for GitHub api request",
71+
},
6772
&cli.BoolFlag{
6873
Name: "no-fetch",
6974
Usage: "Set this flag to prevent fetch of remote branches",
@@ -169,9 +174,10 @@ func runBackport(c *cli.Context) error {
169174
fmt.Printf("* Backporting %s to %s as %s\n", pr, localReleaseBranch, backportBranch)
170175

171176
sha := c.String("cherry-pick")
177+
accessToken := c.String("gh-access-token")
172178
if sha == "" {
173179
var err error
174-
sha, err = determineSHAforPR(ctx, pr)
180+
sha, err = determineSHAforPR(ctx, pr, accessToken)
175181
if err != nil {
176182
return err
177183
}
@@ -427,13 +433,16 @@ func readVersion() string {
427433
return strings.Join(split[:2], ".")
428434
}
429435

430-
func determineSHAforPR(ctx context.Context, prStr string) (string, error) {
436+
func determineSHAforPR(ctx context.Context, prStr, accessToken string) (string, error) {
431437
prNum, err := strconv.Atoi(prStr)
432438
if err != nil {
433439
return "", err
434440
}
435441

436442
client := github.NewClient(http.DefaultClient)
443+
if accessToken != "" {
444+
client = client.WithAuthToken(accessToken)
445+
}
437446

438447
pr, _, err := client.PullRequests.Get(ctx, "go-gitea", "gitea", prNum)
439448
if err != nil {

custom/conf/app.example.ini

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,24 @@ LEVEL = Info
907907
;; Valid site url schemes for user profiles
908908
;VALID_SITE_URL_SCHEMES=http,https
909909

910+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
911+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
912+
;[service.explore]
913+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
914+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
915+
;;
916+
;; Only allow signed in users to view the explore pages.
917+
;REQUIRE_SIGNIN_VIEW = false
918+
;;
919+
;; Disable the users explore page.
920+
;DISABLE_USERS_PAGE = false
921+
;;
922+
;; Disable the organizations explore page.
923+
;DISABLE_ORGANIZATIONS_PAGE = false
924+
;;
925+
;; Disable the code explore page.
926+
;DISABLE_CODE_PAGE = false
927+
;;
910928

911929
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
912930
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ require (
5454
github.com/go-chi/chi/v5 v5.0.13
5555
github.com/go-chi/cors v1.2.1
5656
github.com/go-co-op/gocron v1.37.0
57-
github.com/go-enry/go-enry/v2 v2.8.8
57+
github.com/go-enry/go-enry/v2 v2.9.1
5858
github.com/go-git/go-billy/v5 v5.5.0
5959
github.com/go-git/go-git/v5 v5.12.0
6060
github.com/go-ldap/ldap/v3 v3.4.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
315315
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
316316
github.com/go-co-op/gocron v1.37.0 h1:ZYDJGtQ4OMhTLKOKMIch+/CY70Brbb1dGdooLEhh7b0=
317317
github.com/go-co-op/gocron v1.37.0/go.mod h1:3L/n6BkO7ABj+TrfSVXLRzsP26zmikL4ISkLQ0O8iNY=
318-
github.com/go-enry/go-enry/v2 v2.8.8 h1:EhfxWpw4DQ3WEFB1Y77X8vKqZL0D0EDUUWYDUAIv9/4=
319-
github.com/go-enry/go-enry/v2 v2.8.8/go.mod h1:9yrj4ES1YrbNb1Wb7/PWYr2bpaCXUGRt0uafN0ISyG8=
318+
github.com/go-enry/go-enry/v2 v2.9.1 h1:G9iDteJ/Mc0F4Di5NeQknf83R2OkRbwY9cAYmcqVG6U=
319+
github.com/go-enry/go-enry/v2 v2.9.1/go.mod h1:9yrj4ES1YrbNb1Wb7/PWYr2bpaCXUGRt0uafN0ISyG8=
320320
github.com/go-enry/go-oniguruma v1.2.1 h1:k8aAMuJfMrqm/56SG2lV9Cfti6tC4x8673aHCcBk+eo=
321321
github.com/go-enry/go-oniguruma v1.2.1/go.mod h1:bWDhYP+S6xZQgiRL7wlTScFYBe023B6ilRZbCAD5Hf4=
322322
github.com/go-faster/city v1.0.1 h1:4WAxSZ3V2Ws4QRDrscLEDcibJY8uf41H6AhXDrNDcGw=

models/actions/artifact.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func CreateArtifact(ctx context.Context, t *ActionTask, artifactName, artifactPa
6969
OwnerID: t.OwnerID,
7070
CommitSHA: t.CommitSHA,
7171
Status: int64(ArtifactStatusUploadPending),
72-
ExpiredUnix: timeutil.TimeStamp(time.Now().Unix() + 3600*24*expiredDays),
72+
ExpiredUnix: timeutil.TimeStamp(time.Now().Unix() + timeutil.Day*expiredDays),
7373
}
7474
if _, err := db.GetEngine(ctx).Insert(artifact); err != nil {
7575
return nil, err
@@ -78,6 +78,13 @@ func CreateArtifact(ctx context.Context, t *ActionTask, artifactName, artifactPa
7878
} else if err != nil {
7979
return nil, err
8080
}
81+
82+
if _, err := db.GetEngine(ctx).ID(artifact.ID).Cols("expired_unix").Update(&ActionArtifact{
83+
ExpiredUnix: timeutil.TimeStamp(time.Now().Unix() + timeutil.Day*expiredDays),
84+
}); err != nil {
85+
return nil, err
86+
}
87+
8188
return artifact, nil
8289
}
8390

models/issues/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ func GetPinnedIssues(ctx context.Context, repoID int64, isPull bool) (IssueList,
872872
return issues, nil
873873
}
874874

875-
// IsNewPinnedAllowed returns if a new Issue or Pull request can be pinned
875+
// IsNewPinAllowed returns if a new Issue or Pull request can be pinned
876876
func IsNewPinAllowed(ctx context.Context, repoID int64, isPull bool) (bool, error) {
877877
var maxPin int
878878
_, err := db.GetEngine(ctx).SQL("SELECT COUNT(pin_order) FROM issue WHERE repo_id = ? AND is_pull = ? AND pin_order > 0", repoID, isPull).Get(&maxPin)

models/issues/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ func GetPullRequestByIssueID(ctx context.Context, issueID int64) (*PullRequest,
701701
return pr, pr.LoadAttributes(ctx)
702702
}
703703

704-
// GetPullRequestsByBaseHeadInfo returns the pull request by given base and head
704+
// GetPullRequestByBaseHeadInfo returns the pull request by given base and head
705705
func GetPullRequestByBaseHeadInfo(ctx context.Context, baseID, headID int64, base, head string) (*PullRequest, error) {
706706
pr := &PullRequest{}
707707
sess := db.GetEngine(ctx).

modules/setting/service.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ var Service = struct {
9090

9191
// Explore page settings
9292
Explore struct {
93-
RequireSigninView bool `ini:"REQUIRE_SIGNIN_VIEW"`
94-
DisableUsersPage bool `ini:"DISABLE_USERS_PAGE"`
93+
RequireSigninView bool `ini:"REQUIRE_SIGNIN_VIEW"`
94+
DisableUsersPage bool `ini:"DISABLE_USERS_PAGE"`
95+
DisableOrganizationsPage bool `ini:"DISABLE_ORGANIZATIONS_PAGE"`
96+
DisableCodePage bool `ini:"DISABLE_CODE_PAGE"`
9597
} `ini:"service.explore"`
9698
}{
9799
AllowedUserVisibilityModesSlice: []bool{true, true, true},

routers/api/v1/api.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,20 @@ func reqToken() func(ctx *context.APIContext) {
356356

357357
func reqExploreSignIn() func(ctx *context.APIContext) {
358358
return func(ctx *context.APIContext) {
359-
if setting.Service.Explore.RequireSigninView && !ctx.IsSigned {
359+
if (setting.Service.RequireSignInView || setting.Service.Explore.RequireSigninView) && !ctx.IsSigned {
360360
ctx.Error(http.StatusUnauthorized, "reqExploreSignIn", "you must be signed in to search for users")
361361
}
362362
}
363363
}
364364

365+
func reqUsersExploreEnabled() func(ctx *context.APIContext) {
366+
return func(ctx *context.APIContext) {
367+
if setting.Service.Explore.DisableUsersPage {
368+
ctx.NotFound()
369+
}
370+
}
371+
}
372+
365373
func reqBasicOrRevProxyAuth() func(ctx *context.APIContext) {
366374
return func(ctx *context.APIContext) {
367375
if ctx.IsSigned && setting.Service.EnableReverseProxyAuthAPI && ctx.Data["AuthedMethod"].(string) == auth.ReverseProxyMethodName {
@@ -955,7 +963,7 @@ func Routes() *web.Router {
955963

956964
// Users (requires user scope)
957965
m.Group("/users", func() {
958-
m.Get("/search", reqExploreSignIn(), user.Search)
966+
m.Get("/search", reqExploreSignIn(), reqUsersExploreEnabled(), user.Search)
959967

960968
m.Group("/{username}", func() {
961969
m.Get("", reqExploreSignIn(), user.GetInfo)

routers/api/v1/repo/issue.go

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,80 +41,93 @@ func SearchIssues(ctx *context.APIContext) {
4141
// parameters:
4242
// - name: state
4343
// in: query
44-
// description: whether issue is open or closed
44+
// description: State of the issue
4545
// type: string
46+
// enum: [open, closed, all]
47+
// default: open
4648
// - name: labels
4749
// in: query
48-
// description: comma separated list of labels. Fetch only issues that have any of this labels. Non existent labels are discarded
50+
// description: Comma-separated list of label names. Fetch only issues that have any of these labels. Non existent labels are discarded.
4951
// type: string
5052
// - name: milestones
5153
// in: query
52-
// description: comma separated list of milestone names. Fetch only issues that have any of this milestones. Non existent are discarded
54+
// description: Comma-separated list of milestone names. Fetch only issues that have any of these milestones. Non existent milestones are discarded.
5355
// type: string
5456
// - name: q
5557
// in: query
56-
// description: search string
58+
// description: Search string
5759
// type: string
5860
// - name: priority_repo_id
5961
// in: query
60-
// description: repository to prioritize in the results
62+
// description: Repository ID to prioritize in the results
6163
// type: integer
6264
// format: int64
6365
// - name: type
6466
// in: query
65-
// description: filter by type (issues / pulls) if set
67+
// description: Filter by issue type
6668
// type: string
69+
// enum: [issues, pulls]
6770
// - name: since
6871
// in: query
69-
// description: Only show notifications updated after the given time. This is a timestamp in RFC 3339 format
72+
// description: Only show issues updated after the given time (RFC 3339 format)
7073
// type: string
7174
// format: date-time
72-
// required: false
7375
// - name: before
7476
// in: query
75-
// description: Only show notifications updated before the given time. This is a timestamp in RFC 3339 format
77+
// description: Only show issues updated before the given time (RFC 3339 format)
7678
// type: string
7779
// format: date-time
78-
// required: false
7980
// - name: assigned
8081
// in: query
81-
// description: filter (issues / pulls) assigned to you, default is false
82+
// description: Filter issues or pulls assigned to the authenticated user
8283
// type: boolean
84+
// default: false
8385
// - name: created
8486
// in: query
85-
// description: filter (issues / pulls) created by you, default is false
87+
// description: Filter issues or pulls created by the authenticated user
8688
// type: boolean
89+
// default: false
8790
// - name: mentioned
8891
// in: query
89-
// description: filter (issues / pulls) mentioning you, default is false
92+
// description: Filter issues or pulls mentioning the authenticated user
9093
// type: boolean
94+
// default: false
9195
// - name: review_requested
9296
// in: query
93-
// description: filter pulls requesting your review, default is false
97+
// description: Filter pull requests where the authenticated user's review was requested
9498
// type: boolean
99+
// default: false
95100
// - name: reviewed
96101
// in: query
97-
// description: filter pulls reviewed by you, default is false
102+
// description: Filter pull requests reviewed by the authenticated user
98103
// type: boolean
104+
// default: false
99105
// - name: owner
100106
// in: query
101-
// description: filter by owner
107+
// description: Filter by repository owner
102108
// type: string
103109
// - name: team
104110
// in: query
105-
// description: filter by team (requires organization owner parameter to be provided)
111+
// description: Filter by team (requires organization owner parameter)
106112
// type: string
107113
// - name: page
108114
// in: query
109-
// description: page number of results to return (1-based)
115+
// description: Page number of results to return (1-based)
110116
// type: integer
117+
// minimum: 1
118+
// default: 1
111119
// - name: limit
112120
// in: query
113-
// description: page size of results
121+
// description: Number of items per page
114122
// type: integer
123+
// minimum: 0
115124
// responses:
116125
// "200":
117126
// "$ref": "#/responses/IssueList"
127+
// "400":
128+
// "$ref": "#/responses/error"
129+
// "422":
130+
// "$ref": "#/responses/validationError"
118131

119132
before, since, err := context.GetQueryBeforeSince(ctx.Base)
120133
if err != nil {

routers/web/explore/code.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ const (
2121

2222
// Code render explore code page
2323
func Code(ctx *context.Context) {
24-
if !setting.Indexer.RepoIndexerEnabled {
24+
if !setting.Indexer.RepoIndexerEnabled || setting.Service.Explore.DisableCodePage {
2525
ctx.Redirect(setting.AppSubURL + "/explore")
2626
return
2727
}
2828

29-
ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage
29+
ctx.Data["UsersPageIsDisabled"] = setting.Service.Explore.DisableUsersPage
30+
ctx.Data["OrganizationsPageIsDisabled"] = setting.Service.Explore.DisableOrganizationsPage
3031
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
3132
ctx.Data["Title"] = ctx.Tr("explore")
3233
ctx.Data["PageIsExplore"] = true

routers/web/explore/org.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ import (
1414

1515
// Organizations render explore organizations page
1616
func Organizations(ctx *context.Context) {
17-
ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage
17+
if setting.Service.Explore.DisableOrganizationsPage {
18+
ctx.Redirect(setting.AppSubURL + "/explore")
19+
return
20+
}
21+
22+
ctx.Data["UsersPageIsDisabled"] = setting.Service.Explore.DisableUsersPage
23+
ctx.Data["CodePageIsDisabled"] = setting.Service.Explore.DisableCodePage
1824
ctx.Data["Title"] = ctx.Tr("explore")
1925
ctx.Data["PageIsExplore"] = true
2026
ctx.Data["PageIsExploreOrganizations"] = true

routers/web/explore/repo.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
165165

166166
// Repos render explore repositories page
167167
func Repos(ctx *context.Context) {
168-
ctx.Data["UsersIsDisabled"] = setting.Service.Explore.DisableUsersPage
168+
ctx.Data["UsersPageIsDisabled"] = setting.Service.Explore.DisableUsersPage
169+
ctx.Data["OrganizationsPageIsDisabled"] = setting.Service.Explore.DisableOrganizationsPage
170+
ctx.Data["CodePageIsDisabled"] = setting.Service.Explore.DisableCodePage
169171
ctx.Data["Title"] = ctx.Tr("explore")
170172
ctx.Data["PageIsExplore"] = true
171173
ctx.Data["PageIsExploreRepositories"] = true

routers/web/explore/user.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions,
131131
// Users render explore users page
132132
func Users(ctx *context.Context) {
133133
if setting.Service.Explore.DisableUsersPage {
134-
ctx.Redirect(setting.AppSubURL + "/explore/repos")
134+
ctx.Redirect(setting.AppSubURL + "/explore")
135135
return
136136
}
137+
ctx.Data["OrganizationsPageIsDisabled"] = setting.Service.Explore.DisableOrganizationsPage
138+
ctx.Data["CodePageIsDisabled"] = setting.Service.Explore.DisableCodePage
137139
ctx.Data["Title"] = ctx.Tr("explore")
138140
ctx.Data["PageIsExplore"] = true
139141
ctx.Data["PageIsExploreUsers"] = true

routers/web/user/search.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,24 @@ import (
88

99
"code.gitea.io/gitea/models/db"
1010
user_model "code.gitea.io/gitea/models/user"
11+
"code.gitea.io/gitea/modules/optional"
12+
"code.gitea.io/gitea/modules/setting"
1113
"code.gitea.io/gitea/services/context"
1214
"code.gitea.io/gitea/services/convert"
1315
)
1416

15-
// Search search users
16-
func Search(ctx *context.Context) {
17-
listOptions := db.ListOptions{
18-
Page: ctx.FormInt("page"),
19-
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
20-
}
21-
22-
users, maxResults, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
17+
// SearchCandidates searches candidate users for dropdown list
18+
func SearchCandidates(ctx *context.Context) {
19+
users, _, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
2320
Actor: ctx.Doer,
2421
Keyword: ctx.FormTrim("q"),
25-
UID: ctx.FormInt64("uid"),
2622
Type: user_model.UserTypeIndividual,
27-
IsActive: ctx.FormOptionalBool("active"),
28-
ListOptions: listOptions,
23+
IsActive: optional.Some(true),
24+
ListOptions: db.ListOptions{PageSize: setting.UI.MembersPagingNum},
2925
})
3026
if err != nil {
31-
ctx.JSON(http.StatusInternalServerError, map[string]any{
32-
"ok": false,
33-
"error": err.Error(),
34-
})
27+
ctx.ServerError("Unable to search users", err)
3528
return
3629
}
37-
38-
ctx.SetTotalCountHeader(maxResults)
39-
40-
ctx.JSON(http.StatusOK, map[string]any{
41-
"ok": true,
42-
"data": convert.ToUsers(ctx, ctx.Doer, users),
43-
})
30+
ctx.JSON(http.StatusOK, map[string]any{"data": convert.ToUsers(ctx, ctx.Doer, users)})
4431
}

0 commit comments

Comments
 (0)