Skip to content

Commit f99e4cc

Browse files
authored
Merge branch 'main' into htmx-2-0-5
2 parents 4efdfb1 + ddd1e6c commit f99e4cc

File tree

19 files changed

+58
-31
lines changed

19 files changed

+58
-31
lines changed

models/user/user.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,20 @@ type CountUserFilter struct {
831831
IsActive optional.Option[bool]
832832
}
833833

834+
// HasUsers checks whether there are any users in the database, or only one user exists.
835+
func HasUsers(ctx context.Context) (ret struct {
836+
HasAnyUser, HasOnlyOneUser bool
837+
}, err error,
838+
) {
839+
res, err := db.GetEngine(ctx).Table(&User{}).Cols("id").Limit(2).Query()
840+
if err != nil {
841+
return ret, fmt.Errorf("error checking user existence: %w", err)
842+
}
843+
ret.HasAnyUser = len(res) != 0
844+
ret.HasOnlyOneUser = len(res) == 1
845+
return ret, nil
846+
}
847+
834848
// CountUsers returns number of users.
835849
func CountUsers(ctx context.Context, opts *CountUserFilter) int64 {
836850
return countUsers(ctx, opts)

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ remember_me.compromised = The login token is not valid anymore which may indicat
421421
forgot_password_title= Forgot Password
422422
forgot_password = Forgot password?
423423
need_account = Need an account?
424+
sign_up_tip = You are registering the first account in the system, which has administrator privileges. Please carefully remember your username and password. If you forget the username or password, please refer to the Gitea documentation to recover the account.
424425
sign_up_now = Register now.
425426
sign_up_successful = Account was successfully created. Welcome!
426427
confirmation_mail_sent_prompt_ex = A new confirmation email has been sent to <b>%s</b>. Please check your inbox within the next %s to complete the registration process. If your registration email address is incorrect, you can sign in again and change it.

routers/install/install.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,5 +601,7 @@ func SubmitInstall(ctx *context.Context) {
601601
// InstallDone shows the "post-install" page, makes it easier to develop the page.
602602
// The name is not called as "PostInstall" to avoid misinterpretation as a handler for "POST /install"
603603
func InstallDone(ctx *context.Context) { //nolint
604+
hasUsers, _ := user_model.HasUsers(ctx)
605+
ctx.Data["IsAccountCreated"] = hasUsers.HasAnyUser
604606
ctx.HTML(http.StatusOK, tplPostInstall)
605607
}

routers/web/auth/auth.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,11 @@ func SignOut(ctx *context.Context) {
421421
// SignUp render the register page
422422
func SignUp(ctx *context.Context) {
423423
ctx.Data["Title"] = ctx.Tr("sign_up")
424-
425424
ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
426425

426+
hasUsers, _ := user_model.HasUsers(ctx)
427+
ctx.Data["IsFirstTimeRegistration"] = !hasUsers.HasAnyUser
428+
427429
oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, optional.Some(true))
428430
if err != nil {
429431
ctx.ServerError("UserSignUp", err)
@@ -610,7 +612,13 @@ func createUserInContext(ctx *context.Context, tpl templates.TplName, form any,
610612
// sends a confirmation email if required.
611613
func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth.User) (ok bool) {
612614
// Auto-set admin for the only user.
613-
if user_model.CountUsers(ctx, nil) == 1 {
615+
hasUsers, err := user_model.HasUsers(ctx)
616+
if err != nil {
617+
ctx.ServerError("HasUsers", err)
618+
return false
619+
}
620+
if hasUsers.HasOnlyOneUser {
621+
// the only user is the one just created, will set it as admin
614622
opts := &user_service.UpdateOptions{
615623
IsActive: optional.Some(true),
616624
IsAdmin: user_service.UpdateOptionFieldFromValue(true),

routers/web/explore/repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func Repos(ctx *context.Context) {
151151
ctx.Data["CodePageIsDisabled"] = setting.Service.Explore.DisableCodePage
152152
ctx.Data["Title"] = ctx.Tr("explore")
153153
ctx.Data["PageIsExplore"] = true
154+
ctx.Data["ShowRepoOwnerOnList"] = true
154155
ctx.Data["PageIsExploreRepositories"] = true
155156
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
156157

routers/web/repo/view.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,10 @@ func Forks(ctx *context.Context) {
394394
}
395395

396396
pager := context.NewPagination(int(total), pageSize, page, 5)
397+
ctx.Data["ShowRepoOwnerAvatar"] = true
398+
ctx.Data["ShowRepoOwnerOnList"] = true
397399
ctx.Data["Page"] = pager
398-
399-
ctx.Data["Forks"] = forks
400+
ctx.Data["Repos"] = forks
400401

401402
ctx.HTML(http.StatusOK, tplForks)
402403
}

routers/web/user/profile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func prepareUserProfileTabData(ctx *context.Context, profileDbRepo *repo_model.R
197197
total = int(count)
198198
case "stars":
199199
ctx.Data["PageIsProfileStarList"] = true
200+
ctx.Data["ShowRepoOwnerOnList"] = true
200201
repos, count, err = repo_model.SearchRepository(ctx, repo_model.SearchRepoOptions{
201202
ListOptions: db.ListOptions{
202203
PageSize: pagingNum,

templates/admin/user/view.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{{ctx.Locale.Tr "admin.repositories"}} ({{ctx.Locale.Tr "admin.total" .ReposTotal}})
2727
</h4>
2828
<div class="ui attached segment">
29-
{{template "explore/repo_list" .}}
29+
{{template "shared/repo/list" .}}
3030
</div>
3131
<h4 class="ui top attached header">
3232
{{ctx.Locale.Tr "settings.organization"}} ({{ctx.Locale.Tr "admin.total" .OrgsTotal}})

templates/explore/repos.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<div role="main" aria-label="{{.Title}}" class="page-content explore repositories">
33
{{template "explore/navbar" .}}
44
<div class="ui container">
5-
{{template "shared/repo_search" .}}
6-
{{template "explore/repo_list" .}}
5+
{{template "shared/repo/search" .}}
6+
{{template "shared/repo/list" .}}
77
{{template "base/paginate" .}}
88
</div>
99
</div>

templates/org/home.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
{{if .ProfileReadmeContent}}
99
<div id="readme_profile" class="render-content markup" data-profile-view-as-member="{{.IsViewingOrgAsMember}}">{{.ProfileReadmeContent}}</div>
1010
{{end}}
11-
{{template "shared/repo_search" .}}
12-
{{template "explore/repo_list" .}}
11+
{{template "shared/repo/search" .}}
12+
{{template "shared/repo/list" .}}
1313
{{template "base/paginate" .}}
1414
</div>
1515

0 commit comments

Comments
 (0)