Skip to content

Commit 4e4c21e

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated licenses and gitignores Revert 100% label max-width (go-gitea#30481) Improve flex ellipsis (go-gitea#30479) Remove fomantic button module (go-gitea#30475) Improve "must-change-password" logic and document (go-gitea#30472) Fix commitstatus summary (go-gitea#30431) Remove fomantic menu module (go-gitea#30325) Use `flex-container` for dashboard layout (go-gitea#30214) Rewrite and restyle reaction selector and enable no-sizzle eslint rule (go-gitea#30453) Pulse page improvements (go-gitea#30149)
2 parents d51ac9b + 708e87e commit 4e4c21e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+4198
-8254
lines changed

.eslintrc.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ rules:
318318
jquery/no-serialize: [2]
319319
jquery/no-show: [2]
320320
jquery/no-size: [2]
321-
jquery/no-sizzle: [0]
321+
jquery/no-sizzle: [2]
322322
jquery/no-slide: [0]
323323
jquery/no-submit: [0]
324324
jquery/no-text: [0]
@@ -470,7 +470,7 @@ rules:
470470
no-jquery/no-selector-prop: [2]
471471
no-jquery/no-serialize: [2]
472472
no-jquery/no-size: [2]
473-
no-jquery/no-sizzle: [0]
473+
no-jquery/no-sizzle: [2]
474474
no-jquery/no-slide: [2]
475475
no-jquery/no-sub: [2]
476476
no-jquery/no-support: [2]

cmd/admin_user_change_password.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var microcmdUserChangePassword = &cli.Command{
3636
&cli.BoolFlag{
3737
Name: "must-change-password",
3838
Usage: "User must change password",
39+
Value: true,
3940
},
4041
},
4142
}
@@ -57,23 +58,18 @@ func runChangePassword(c *cli.Context) error {
5758
return err
5859
}
5960

60-
var mustChangePassword optional.Option[bool]
61-
if c.IsSet("must-change-password") {
62-
mustChangePassword = optional.Some(c.Bool("must-change-password"))
63-
}
64-
6561
opts := &user_service.UpdateAuthOptions{
6662
Password: optional.Some(c.String("password")),
67-
MustChangePassword: mustChangePassword,
63+
MustChangePassword: optional.Some(c.Bool("must-change-password")),
6864
}
6965
if err := user_service.UpdateAuth(ctx, user, opts); err != nil {
7066
switch {
7167
case errors.Is(err, password.ErrMinLength):
72-
return fmt.Errorf("Password is not long enough. Needs to be at least %d", setting.MinPasswordLength)
68+
return fmt.Errorf("password is not long enough, needs to be at least %d characters", setting.MinPasswordLength)
7369
case errors.Is(err, password.ErrComplexity):
74-
return errors.New("Password does not meet complexity requirements")
70+
return errors.New("password does not meet complexity requirements")
7571
case errors.Is(err, password.ErrIsPwned):
76-
return errors.New("The password you chose is on a list of stolen passwords previously exposed in public data breaches. Please try again with a different password.\nFor more details, see https://haveibeenpwned.com/Passwords")
72+
return errors.New("the password is in a list of stolen passwords previously exposed in public data breaches, please try again with a different password, to see more details: https://haveibeenpwned.com/Passwords")
7773
default:
7874
return err
7975
}

cmd/admin_user_create.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99

1010
auth_model "code.gitea.io/gitea/models/auth"
11+
"code.gitea.io/gitea/models/db"
1112
user_model "code.gitea.io/gitea/models/user"
1213
pwd "code.gitea.io/gitea/modules/auth/password"
1314
"code.gitea.io/gitea/modules/optional"
@@ -46,8 +47,9 @@ var microcmdUserCreate = &cli.Command{
4647
Usage: "Generate a random password for the user",
4748
},
4849
&cli.BoolFlag{
49-
Name: "must-change-password",
50-
Usage: "Set this option to false to prevent forcing the user to change their password after initial login, (Default: true)",
50+
Name: "must-change-password",
51+
Usage: "Set to false to prevent forcing the user to change their password after initial login",
52+
DisableDefaultText: true,
5153
},
5254
&cli.IntFlag{
5355
Name: "random-password-length",
@@ -71,10 +73,10 @@ func runCreateUser(c *cli.Context) error {
7173
}
7274

7375
if c.IsSet("name") && c.IsSet("username") {
74-
return errors.New("Cannot set both --name and --username flags")
76+
return errors.New("cannot set both --name and --username flags")
7577
}
7678
if !c.IsSet("name") && !c.IsSet("username") {
77-
return errors.New("One of --name or --username flags must be set")
79+
return errors.New("one of --name or --username flags must be set")
7880
}
7981

8082
if c.IsSet("password") && c.IsSet("random-password") {
@@ -110,17 +112,21 @@ func runCreateUser(c *cli.Context) error {
110112
return errors.New("must set either password or random-password flag")
111113
}
112114

113-
// always default to true
114-
changePassword := true
115-
116-
// If this is the first user being created.
117-
// Take it as the admin and don't force a password update.
118-
if n := user_model.CountUsers(ctx, nil); n == 0 {
119-
changePassword = false
120-
}
121-
115+
isAdmin := c.Bool("admin")
116+
mustChangePassword := true // always default to true
122117
if c.IsSet("must-change-password") {
123-
changePassword = c.Bool("must-change-password")
118+
// if the flag is set, use the value provided by the user
119+
mustChangePassword = c.Bool("must-change-password")
120+
} else {
121+
// check whether there are users in the database
122+
hasUserRecord, err := db.IsTableNotEmpty(&user_model.User{})
123+
if err != nil {
124+
return fmt.Errorf("IsTableNotEmpty: %w", err)
125+
}
126+
if !hasUserRecord && isAdmin {
127+
// if this is the first admin being created, don't force to change password (keep the old behavior)
128+
mustChangePassword = false
129+
}
124130
}
125131

126132
restricted := optional.None[bool]()
@@ -136,8 +142,8 @@ func runCreateUser(c *cli.Context) error {
136142
Name: username,
137143
Email: c.String("email"),
138144
Passwd: password,
139-
IsAdmin: c.Bool("admin"),
140-
MustChangePassword: changePassword,
145+
IsAdmin: isAdmin,
146+
MustChangePassword: mustChangePassword,
141147
Visibility: visibility,
142148
}
143149

docs/content/administration/command-line.en-us.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ Admin operations:
8383
- `--email value`: Email. Required.
8484
- `--admin`: If provided, this makes the user an admin. Optional.
8585
- `--access-token`: If provided, an access token will be created for the user. Optional. (default: false).
86-
- `--must-change-password`: If provided, the created user will be required to choose a newer password after the
87-
initial login. Optional. (default: true).
86+
- `--must-change-password`: The created user will be required to set a new password after the initial login, default: true. It could be disabled by `--must-change-password=false`.
8887
- `--random-password`: If provided, a randomly generated password will be used as the password of the created
8988
user. The value of `--password` will be discarded. Optional.
9089
- `--random-password-length`: If provided, it will be used to configure the length of the randomly generated
@@ -95,7 +94,7 @@ Admin operations:
9594
- Options:
9695
- `--username value`, `-u value`: Username. Required.
9796
- `--password value`, `-p value`: New password. Required.
98-
- `--must-change-password`: If provided, the user is required to choose a new password after the login. Optional.
97+
- `--must-change-password`: The user is required to set a new password after the login, default: true. It could be disabled by `--must-change-password=false`.
9998
- Examples:
10099
- `gitea admin user change-password --username myname --password asecurepassword`
101100
- `must-change-password`:

models/db/engine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ func MaxBatchInsertSize(bean any) int {
284284
}
285285

286286
// IsTableNotEmpty returns true if table has at least one record
287-
func IsTableNotEmpty(tableName string) (bool, error) {
288-
return x.Table(tableName).Exist()
287+
func IsTableNotEmpty(beanOrTableName any) (bool, error) {
288+
return x.Table(beanOrTableName).Exist()
289289
}
290290

291291
// DeleteAllRecords will delete all the records of this table

models/git/commit_status_summary.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ import (
1515

1616
// CommitStatusSummary holds the latest commit Status of a single Commit
1717
type CommitStatusSummary struct {
18-
ID int64 `xorm:"pk autoincr"`
19-
RepoID int64 `xorm:"INDEX UNIQUE(repo_id_sha)"`
20-
SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_id_sha)"`
21-
State api.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"`
18+
ID int64 `xorm:"pk autoincr"`
19+
RepoID int64 `xorm:"INDEX UNIQUE(repo_id_sha)"`
20+
SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_id_sha)"`
21+
State api.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"`
22+
TargetURL string `xorm:"TEXT"`
2223
}
2324

2425
func init() {
@@ -44,9 +45,10 @@ func GetLatestCommitStatusForRepoAndSHAs(ctx context.Context, repoSHAs []RepoSHA
4445
commitStatuses := make([]*CommitStatus, 0, len(repoSHAs))
4546
for _, summary := range summaries {
4647
commitStatuses = append(commitStatuses, &CommitStatus{
47-
RepoID: summary.RepoID,
48-
SHA: summary.SHA,
49-
State: summary.State,
48+
RepoID: summary.RepoID,
49+
SHA: summary.SHA,
50+
State: summary.State,
51+
TargetURL: summary.TargetURL,
5052
})
5153
}
5254
return commitStatuses, nil
@@ -61,22 +63,24 @@ func UpdateCommitStatusSummary(ctx context.Context, repoID int64, sha string) er
6163
// mysql will return 0 when update a record which state hasn't been changed which behaviour is different from other database,
6264
// so we need to use insert in on duplicate
6365
if setting.Database.Type.IsMySQL() {
64-
_, err := db.GetEngine(ctx).Exec("INSERT INTO commit_status_summary (repo_id,sha,state) VALUES (?,?,?) ON DUPLICATE KEY UPDATE state=?",
65-
repoID, sha, state.State, state.State)
66+
_, err := db.GetEngine(ctx).Exec("INSERT INTO commit_status_summary (repo_id,sha,state,target_url) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE state=?",
67+
repoID, sha, state.State, state.TargetURL, state.State)
6668
return err
6769
}
6870

6971
if cnt, err := db.GetEngine(ctx).Where("repo_id=? AND sha=?", repoID, sha).
70-
Cols("state").
72+
Cols("state, target_url").
7173
Update(&CommitStatusSummary{
72-
State: state.State,
74+
State: state.State,
75+
TargetURL: state.TargetURL,
7376
}); err != nil {
7477
return err
7578
} else if cnt == 0 {
7679
_, err = db.GetEngine(ctx).Insert(&CommitStatusSummary{
77-
RepoID: repoID,
78-
SHA: sha,
79-
State: state.State,
80+
RepoID: repoID,
81+
SHA: sha,
82+
State: state.State,
83+
TargetURL: state.TargetURL,
8084
})
8185
return err
8286
}

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,8 @@ var migrations = []Migration{
580580
NewMigration("Add unique index for project issue table", v1_23.AddUniqueIndexForProjectIssue),
581581
// v295 -> v296
582582
NewMigration("Add commit status summary table", v1_23.AddCommitStatusSummary),
583+
// v296 -> v297
584+
NewMigration("Add missing field of commit status summary table", v1_23.AddCommitStatusSummary2),
583585
}
584586

585587
// GetCurrentDBVersion returns the current db version

models/migrations/v1_23/v296.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_23 //nolint
5+
6+
import "xorm.io/xorm"
7+
8+
func AddCommitStatusSummary2(x *xorm.Engine) error {
9+
type CommitStatusSummary struct {
10+
ID int64 `xorm:"pk autoincr"`
11+
TargetURL string `xorm:"TEXT"`
12+
}
13+
// there is no migrations because if there is no data on this table, it will fall back to get data
14+
// from commit status
15+
return x.Sync(new(CommitStatusSummary))
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (C) 2006,2007,2009 NTT (Nippon Telegraph and Telephone
2+
Corporation). All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions
6+
are met:
7+
8+
1. Redistributions of source code must retain the above
9+
copyright notice, this list of conditions and the following
10+
disclaimer as the first lines of this file unmodified.
11+
12+
2. Redistributions in binary form must reproduce the above
13+
copyright notice, this list of conditions and the following
14+
disclaimer in the documentation and/or other materials provided
15+
with the distribution.
16+
17+
THIS SOFTWARE IS PROVIDED BY NTT "AS IS" AND ANY EXPRESS OR IMPLIED
18+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL NTT BE LIABLE FOR ANY DIRECT,
21+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27+
OF THE POSSIBILITY OF SUCH DAMAGE.

options/license/Sun-PPP-2000

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) 2000 by Sun Microsystems, Inc.
2+
All rights reserved.
3+
4+
Permission to use, copy, modify, and distribute this software and its
5+
documentation is hereby granted, provided that the above copyright
6+
notice appears in all copies.
7+
8+
SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
9+
THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
10+
TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
11+
PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
12+
ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
13+
DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES

options/license/pkgconf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Permission to use, copy, modify, and/or distribute this software for any
2+
purpose with or without fee is hereby granted, provided that the above
3+
copyright notice and this permission notice appear in all copies.
4+
5+
This software is provided 'as is' and without any warranty, express or
6+
implied. In no event shall the authors be liable for any damages arising
7+
from the use of this software.

routers/web/repo/issue.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,7 +3318,6 @@ func ChangeIssueReaction(ctx *context.Context) {
33183318
}
33193319

33203320
html, err := ctx.RenderToHTML(tplReactions, map[string]any{
3321-
"ctxData": ctx.Data,
33223321
"ActionURL": fmt.Sprintf("%s/issues/%d/reactions", ctx.Repo.RepoLink, issue.Index),
33233322
"Reactions": issue.Reactions.GroupByType(),
33243323
})
@@ -3425,7 +3424,6 @@ func ChangeCommentReaction(ctx *context.Context) {
34253424
}
34263425

34273426
html, err := ctx.RenderToHTML(tplReactions, map[string]any{
3428-
"ctxData": ctx.Data,
34293427
"ActionURL": fmt.Sprintf("%s/comments/%d/reactions", ctx.Repo.RepoLink, comment.ID),
34303428
"Reactions": comment.Reactions.GroupByType(),
34313429
})

services/context/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func NewTemplateContextForWeb(ctx *Context) TemplateContext {
101101
tmplCtx := NewTemplateContext(ctx)
102102
tmplCtx["Locale"] = ctx.Base.Locale
103103
tmplCtx["AvatarUtils"] = templates.NewAvatarUtils(ctx)
104+
tmplCtx["RootData"] = ctx.Data
104105
return tmplCtx
105106
}
106107

templates/admin/notice.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
</div>
5050
</div>
5151
</div>
52-
<button class="ui small teal button" id="delete-selection" data-link="{{.Link}}/delete" data-redirect="?page={{.Page.Paginater.Current}}">
52+
<button class="ui small button" id="delete-selection" data-link="{{.Link}}/delete" data-redirect="?page={{.Page.Paginater.Current}}">
5353
<span class="text">{{ctx.Locale.Tr "admin.notices.delete_selected"}}</span>
5454
</button>
5555
</th>

templates/admin/repo/unadopted.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<input type="hidden" name="action" value="delete">
5555
<input type="hidden" name="q" value="{{$.Keyword}}">
5656
<input type="hidden" name="page" value="{{$.CurrentPage}}">
57-
{{template "base/modal_actions_confirm" (dict "ModalButtonColors" "yellow")}}
57+
{{template "base/modal_actions_confirm"}}
5858
</form>
5959
</div>
6060
</div>

templates/base/modal_actions_confirm.tmpl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{{/*
22
Two buttons (negative, positive):
33
* ModalButtonTypes: "yes" (default) or "confirm"
4-
* ModalButtonColors: "primary" (default) / "blue" / "yellow"
54
* ModalButtonCancelText
65
* ModalButtonOkText
76

@@ -22,14 +21,7 @@ The ".ok.button" and ".cancel.button" selectors are also used by Fomantic Modal
2221
{{end}}
2322
{{if .ModalButtonCancelText}}{{$textNegitive = .ModalButtonCancelText}}{{end}}
2423
{{if .ModalButtonOkText}}{{$textPositive = .ModalButtonOkText}}{{end}}
25-
26-
{{$stylePositive := "primary"}}
27-
{{if eq .ModalButtonColors "blue"}}
28-
{{$stylePositive = "blue"}}
29-
{{else if eq .ModalButtonColors "yellow"}}
30-
{{$stylePositive = "yellow"}}
31-
{{end}}
3224
<button class="ui cancel button">{{svg "octicon-x"}} {{$textNegitive}}</button>
33-
<button class="ui {{$stylePositive}} ok button">{{svg "octicon-check"}} {{$textPositive}}</button>
25+
<button class="ui primary ok button">{{svg "octicon-check"}} {{$textPositive}}</button>
3426
{{end}}
3527
</div>

0 commit comments

Comments
 (0)