forked from gitea/gitea
1
0
Fork 0

Start to migrate from `util.OptionalBool` to `optional.Option[bool]` (#29329)

just create transition helper and migrate two structs
This commit is contained in:
6543 2024-02-23 03:18:33 +01:00 committed by GitHub
parent b748d62b46
commit 7fbdb60fc1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 84 additions and 64 deletions

View File

@ -10,8 +10,8 @@ import (
auth_model "code.gitea.io/gitea/models/auth" auth_model "code.gitea.io/gitea/models/auth"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
pwd "code.gitea.io/gitea/modules/auth/password" pwd "code.gitea.io/gitea/modules/auth/password"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
@ -123,10 +123,10 @@ func runCreateUser(c *cli.Context) error {
changePassword = c.Bool("must-change-password") changePassword = c.Bool("must-change-password")
} }
restricted := util.OptionalBoolNone restricted := optional.None[bool]()
if c.IsSet("restricted") { if c.IsSet("restricted") {
restricted = util.OptionalBoolOf(c.Bool("restricted")) restricted = optional.Some(c.Bool("restricted"))
} }
// default user visibility in app.ini // default user visibility in app.ini
@ -142,7 +142,7 @@ func runCreateUser(c *cli.Context) error {
} }
overwriteDefault := &user_model.CreateUserOverwriteOptions{ overwriteDefault := &user_model.CreateUserOverwriteOptions{
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
IsRestricted: restricted, IsRestricted: restricted,
} }

View File

@ -9,7 +9,7 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/optional"
"xorm.io/builder" "xorm.io/builder"
) )
@ -67,7 +67,7 @@ type FindBranchOptions struct {
db.ListOptions db.ListOptions
RepoID int64 RepoID int64
ExcludeBranchNames []string ExcludeBranchNames []string
IsDeletedBranch util.OptionalBool IsDeletedBranch optional.Option[bool]
OrderBy string OrderBy string
Keyword string Keyword string
} }
@ -81,8 +81,8 @@ func (opts FindBranchOptions) ToConds() builder.Cond {
if len(opts.ExcludeBranchNames) > 0 { if len(opts.ExcludeBranchNames) > 0 {
cond = cond.And(builder.NotIn("name", opts.ExcludeBranchNames)) cond = cond.And(builder.NotIn("name", opts.ExcludeBranchNames))
} }
if !opts.IsDeletedBranch.IsNone() { if opts.IsDeletedBranch.Has() {
cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.IsTrue()}) cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.Value()})
} }
if opts.Keyword != "" { if opts.Keyword != "" {
cond = cond.And(builder.Like{"name", opts.Keyword}) cond = cond.And(builder.Like{"name", opts.Keyword})
@ -92,7 +92,7 @@ func (opts FindBranchOptions) ToConds() builder.Cond {
func (opts FindBranchOptions) ToOrders() string { func (opts FindBranchOptions) ToOrders() string {
orderBy := opts.OrderBy orderBy := opts.OrderBy
if !opts.IsDeletedBranch.IsFalse() { // if deleted branch included, put them at the end if opts.IsDeletedBranch.ValueOrDefault(true) { // if deleted branch included, put them at the end
if orderBy != "" { if orderBy != "" {
orderBy += ", " orderBy += ", "
} }

View File

@ -13,7 +13,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/optional"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -50,7 +50,7 @@ func TestGetDeletedBranches(t *testing.T) {
branches, err := db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{ branches, err := db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{
ListOptions: db.ListOptionsAll, ListOptions: db.ListOptionsAll,
RepoID: repo.ID, RepoID: repo.ID,
IsDeletedBranch: util.OptionalBoolTrue, IsDeletedBranch: optional.Some(true),
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, branches, 2) assert.Len(t, branches, 2)

View File

@ -8,7 +8,7 @@ import (
"sort" "sort"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/optional"
"github.com/gobwas/glob" "github.com/gobwas/glob"
) )
@ -56,7 +56,7 @@ func FindAllMatchedBranches(ctx context.Context, repoID int64, ruleName string)
Page: page, Page: page,
}, },
RepoID: repoID, RepoID: repoID,
IsDeletedBranch: util.OptionalBoolFalse, IsDeletedBranch: optional.Some(false),
}) })
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -25,6 +25,7 @@ import (
"code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
@ -573,14 +574,14 @@ func IsUsableUsername(name string) error {
// CreateUserOverwriteOptions are an optional options who overwrite system defaults on user creation // CreateUserOverwriteOptions are an optional options who overwrite system defaults on user creation
type CreateUserOverwriteOptions struct { type CreateUserOverwriteOptions struct {
KeepEmailPrivate util.OptionalBool KeepEmailPrivate optional.Option[bool]
Visibility *structs.VisibleType Visibility *structs.VisibleType
AllowCreateOrganization util.OptionalBool AllowCreateOrganization optional.Option[bool]
EmailNotificationsPreference *string EmailNotificationsPreference *string
MaxRepoCreation *int MaxRepoCreation *int
Theme *string Theme *string
IsRestricted util.OptionalBool IsRestricted optional.Option[bool]
IsActive util.OptionalBool IsActive optional.Option[bool]
} }
// CreateUser creates record of a new user. // CreateUser creates record of a new user.
@ -607,14 +608,14 @@ func CreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOve
// overwrite defaults if set // overwrite defaults if set
if len(overwriteDefault) != 0 && overwriteDefault[0] != nil { if len(overwriteDefault) != 0 && overwriteDefault[0] != nil {
overwrite := overwriteDefault[0] overwrite := overwriteDefault[0]
if !overwrite.KeepEmailPrivate.IsNone() { if overwrite.KeepEmailPrivate.Has() {
u.KeepEmailPrivate = overwrite.KeepEmailPrivate.IsTrue() u.KeepEmailPrivate = overwrite.KeepEmailPrivate.Value()
} }
if overwrite.Visibility != nil { if overwrite.Visibility != nil {
u.Visibility = *overwrite.Visibility u.Visibility = *overwrite.Visibility
} }
if !overwrite.AllowCreateOrganization.IsNone() { if overwrite.AllowCreateOrganization.Has() {
u.AllowCreateOrganization = overwrite.AllowCreateOrganization.IsTrue() u.AllowCreateOrganization = overwrite.AllowCreateOrganization.Value()
} }
if overwrite.EmailNotificationsPreference != nil { if overwrite.EmailNotificationsPreference != nil {
u.EmailNotificationsPreference = *overwrite.EmailNotificationsPreference u.EmailNotificationsPreference = *overwrite.EmailNotificationsPreference
@ -625,11 +626,11 @@ func CreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOve
if overwrite.Theme != nil { if overwrite.Theme != nil {
u.Theme = *overwrite.Theme u.Theme = *overwrite.Theme
} }
if !overwrite.IsRestricted.IsNone() { if overwrite.IsRestricted.Has() {
u.IsRestricted = overwrite.IsRestricted.IsTrue() u.IsRestricted = overwrite.IsRestricted.Value()
} }
if !overwrite.IsActive.IsNone() { if overwrite.IsActive.Has() {
u.IsActive = overwrite.IsActive.IsTrue() u.IsActive = overwrite.IsActive.Value()
} }
} }

View File

@ -27,6 +27,7 @@ import (
"code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/gitrepo"
code_indexer "code.gitea.io/gitea/modules/indexer/code" code_indexer "code.gitea.io/gitea/modules/indexer/code"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -671,7 +672,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc {
branchOpts := git_model.FindBranchOptions{ branchOpts := git_model.FindBranchOptions{
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
IsDeletedBranch: util.OptionalBoolFalse, IsDeletedBranch: optional.Some(false),
ListOptions: db.ListOptionsAll, ListOptions: db.ListOptionsAll,
} }
branchesTotal, err := db.Count[git_model.Branch](ctx, branchOpts) branchesTotal, err := db.Count[git_model.Branch](ctx, branchOpts)

View File

@ -6,8 +6,6 @@ package optional
import ( import (
"testing" "testing"
"code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -30,7 +28,8 @@ func TestOption(t *testing.T) {
var ptr *int var ptr *int
assert.False(t, FromPtr(ptr).Has()) assert.False(t, FromPtr(ptr).Has())
opt1 := FromPtr(util.ToPointer(1)) int1 := 1
opt1 := FromPtr(&int1)
assert.True(t, opt1.Has()) assert.True(t, opt1.Has())
assert.Equal(t, int(1), opt1.Value()) assert.Equal(t, int(1), opt1.Value())

View File

@ -11,6 +11,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"code.gitea.io/gitea/modules/optional"
"golang.org/x/text/cases" "golang.org/x/text/cases"
"golang.org/x/text/language" "golang.org/x/text/language"
) )
@ -42,6 +44,22 @@ func (o OptionalBool) IsNone() bool {
return o == OptionalBoolNone return o == OptionalBoolNone
} }
// ToGeneric converts OptionalBool to optional.Option[bool]
func (o OptionalBool) ToGeneric() optional.Option[bool] {
if o.IsNone() {
return optional.None[bool]()
}
return optional.Some[bool](o.IsTrue())
}
// OptionalBoolFromGeneric converts optional.Option[bool] to OptionalBool
func OptionalBoolFromGeneric(o optional.Option[bool]) OptionalBool {
if o.Has() {
return OptionalBoolOf(o.Value())
}
return OptionalBoolNone
}
// OptionalBoolOf get the corresponding OptionalBool of a bool // OptionalBoolOf get the corresponding OptionalBool of a bool
func OptionalBoolOf(b bool) OptionalBool { func OptionalBoolOf(b bool) OptionalBool {
if b { if b {

View File

@ -21,7 +21,6 @@ import (
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/user" "code.gitea.io/gitea/routers/api/v1/user"
"code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/routers/api/v1/utils"
@ -117,11 +116,8 @@ func CreateUser(ctx *context.APIContext) {
} }
overwriteDefault := &user_model.CreateUserOverwriteOptions{ overwriteDefault := &user_model.CreateUserOverwriteOptions{
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
} IsRestricted: optional.FromPtr(form.Restricted),
if form.Restricted != nil {
overwriteDefault.IsRestricted = util.OptionalBoolOf(*form.Restricted)
} }
if form.Visibility != "" { if form.Visibility != "" {

View File

@ -17,9 +17,9 @@ import (
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/optional"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/routers/api/v1/utils"
"code.gitea.io/gitea/services/convert" "code.gitea.io/gitea/services/convert"
@ -141,7 +141,7 @@ func DeleteBranch(ctx *context.APIContext) {
// check whether branches of this repository has been synced // check whether branches of this repository has been synced
totalNumOfBranches, err := db.Count[git_model.Branch](ctx, git_model.FindBranchOptions{ totalNumOfBranches, err := db.Count[git_model.Branch](ctx, git_model.FindBranchOptions{
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
IsDeletedBranch: util.OptionalBoolFalse, IsDeletedBranch: optional.Some(false),
}) })
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "CountBranches", err) ctx.Error(http.StatusInternalServerError, "CountBranches", err)
@ -340,7 +340,7 @@ func ListBranches(ctx *context.APIContext) {
branchOpts := git_model.FindBranchOptions{ branchOpts := git_model.FindBranchOptions{
ListOptions: listOptions, ListOptions: listOptions,
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
IsDeletedBranch: util.OptionalBoolFalse, IsDeletedBranch: optional.Some(false),
} }
var err error var err error
totalNumOfBranches, err = db.Count[git_model.Branch](ctx, branchOpts) totalNumOfBranches, err = db.Count[git_model.Branch](ctx, branchOpts)

View File

@ -25,12 +25,12 @@ import (
"code.gitea.io/gitea/modules/generate" "code.gitea.io/gitea/modules/generate"
"code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/templates" "code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/modules/translation"
"code.gitea.io/gitea/modules/user" "code.gitea.io/gitea/modules/user"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/routers/common" "code.gitea.io/gitea/routers/common"
@ -533,8 +533,8 @@ func SubmitInstall(ctx *context.Context) {
IsAdmin: true, IsAdmin: true,
} }
overwriteDefault := &user_model.CreateUserOverwriteOptions{ overwriteDefault := &user_model.CreateUserOverwriteOptions{
IsRestricted: util.OptionalBoolFalse, IsRestricted: optional.Some(false),
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
} }
if err = user_model.CreateUser(ctx, u, overwriteDefault); err != nil { if err = user_model.CreateUser(ctx, u, overwriteDefault); err != nil {

View File

@ -140,7 +140,7 @@ func NewUserPost(ctx *context.Context) {
} }
overwriteDefault := &user_model.CreateUserOverwriteOptions{ overwriteDefault := &user_model.CreateUserOverwriteOptions{
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
Visibility: &form.Visibility, Visibility: &form.Visibility,
} }

View File

@ -979,7 +979,7 @@ func SignInOAuthCallback(ctx *context.Context) {
} }
overwriteDefault := &user_model.CreateUserOverwriteOptions{ overwriteDefault := &user_model.CreateUserOverwriteOptions{
IsActive: util.OptionalBoolOf(!setting.OAuth2Client.RegisterEmailConfirm && !setting.Service.RegisterManualConfirm), IsActive: optional.Some(!setting.OAuth2Client.RegisterEmailConfirm && !setting.Service.RegisterManualConfirm),
} }
source := authSource.Cfg.(*oauth2.Source) source := authSource.Cfg.(*oauth2.Source)

View File

@ -31,6 +31,7 @@ import (
"code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/typesniffer" "code.gitea.io/gitea/modules/typesniffer"
@ -700,7 +701,7 @@ func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repositor
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
ListAll: true, ListAll: true,
}, },
IsDeletedBranch: util.OptionalBoolFalse, IsDeletedBranch: optional.Some(false),
}) })
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -757,7 +758,7 @@ func CompareDiff(ctx *context.Context) {
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
ListAll: true, ListAll: true,
}, },
IsDeletedBranch: util.OptionalBoolFalse, IsDeletedBranch: optional.Some(false),
}) })
if err != nil { if err != nil {
ctx.ServerError("GetBranches", err) ctx.ServerError("GetBranches", err)

View File

@ -32,6 +32,7 @@ import (
"code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/gitrepo"
issue_template "code.gitea.io/gitea/modules/issue/template" issue_template "code.gitea.io/gitea/modules/issue/template"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/upload" "code.gitea.io/gitea/modules/upload"
@ -186,7 +187,7 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository {
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
ListAll: true, ListAll: true,
}, },
IsDeletedBranch: util.OptionalBoolFalse, IsDeletedBranch: optional.Some(false),
// Add it as the first option // Add it as the first option
ExcludeBranchNames: []string{ctx.Repo.Repository.DefaultBranch}, ExcludeBranchNames: []string{ctx.Repo.Repository.DefaultBranch},
}) })

View File

@ -24,6 +24,7 @@ import (
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/storage"
@ -685,7 +686,7 @@ type branchTagSearchResponse struct {
func GetBranchesList(ctx *context.Context) { func GetBranchesList(ctx *context.Context) {
branchOpts := git_model.FindBranchOptions{ branchOpts := git_model.FindBranchOptions{
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
IsDeletedBranch: util.OptionalBoolFalse, IsDeletedBranch: optional.Some(false),
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
ListAll: true, ListAll: true,
}, },
@ -720,7 +721,7 @@ func GetTagList(ctx *context.Context) {
func PrepareBranchList(ctx *context.Context) { func PrepareBranchList(ctx *context.Context) {
branchOpts := git_model.FindBranchOptions{ branchOpts := git_model.FindBranchOptions{
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
IsDeletedBranch: util.OptionalBoolFalse, IsDeletedBranch: optional.Some(false),
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
ListAll: true, ListAll: true,
}, },

View File

@ -10,8 +10,8 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/modules/web/middleware"
gouuid "github.com/google/uuid" gouuid "github.com/google/uuid"
@ -161,7 +161,7 @@ func (r *ReverseProxy) newUser(req *http.Request) *user_model.User {
} }
overwriteDefault := user_model.CreateUserOverwriteOptions{ overwriteDefault := user_model.CreateUserOverwriteOptions{
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
} }
if err := user_model.CreateUser(req.Context(), user, &overwriteDefault); err != nil { if err := user_model.CreateUser(req.Context(), user, &overwriteDefault); err != nil {

View File

@ -13,7 +13,6 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
auth_module "code.gitea.io/gitea/modules/auth" auth_module "code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/optional" "code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/util"
source_service "code.gitea.io/gitea/services/auth/source" source_service "code.gitea.io/gitea/services/auth/source"
user_service "code.gitea.io/gitea/services/user" user_service "code.gitea.io/gitea/services/user"
) )
@ -85,8 +84,8 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
IsAdmin: sr.IsAdmin, IsAdmin: sr.IsAdmin,
} }
overwriteDefault := &user_model.CreateUserOverwriteOptions{ overwriteDefault := &user_model.CreateUserOverwriteOptions{
IsRestricted: util.OptionalBoolOf(sr.IsRestricted), IsRestricted: optional.Some(sr.IsRestricted),
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
} }
err := user_model.CreateUser(ctx, user, overwriteDefault) err := user_model.CreateUser(ctx, user, overwriteDefault)

View File

@ -16,7 +16,6 @@ import (
"code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional" "code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/util"
source_service "code.gitea.io/gitea/services/auth/source" source_service "code.gitea.io/gitea/services/auth/source"
user_service "code.gitea.io/gitea/services/user" user_service "code.gitea.io/gitea/services/user"
) )
@ -125,8 +124,8 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
IsAdmin: su.IsAdmin, IsAdmin: su.IsAdmin,
} }
overwriteDefault := &user_model.CreateUserOverwriteOptions{ overwriteDefault := &user_model.CreateUserOverwriteOptions{
IsRestricted: util.OptionalBoolOf(su.IsRestricted), IsRestricted: optional.Some(su.IsRestricted),
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
} }
err = user_model.CreateUser(ctx, usr, overwriteDefault) err = user_model.CreateUser(ctx, usr, overwriteDefault)

View File

@ -11,8 +11,8 @@ import (
"code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/auth"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/auth/pam" "code.gitea.io/gitea/modules/auth/pam"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"github.com/google/uuid" "github.com/google/uuid"
) )
@ -60,7 +60,7 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
LoginName: userName, // This is what the user typed in LoginName: userName, // This is what the user typed in
} }
overwriteDefault := &user_model.CreateUserOverwriteOptions{ overwriteDefault := &user_model.CreateUserOverwriteOptions{
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
} }
if err := user_model.CreateUser(ctx, user, overwriteDefault); err != nil { if err := user_model.CreateUser(ctx, user, overwriteDefault); err != nil {

View File

@ -12,6 +12,7 @@ import (
auth_model "code.gitea.io/gitea/models/auth" auth_model "code.gitea.io/gitea/models/auth"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
) )
@ -75,7 +76,7 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
LoginName: userName, LoginName: userName,
} }
overwriteDefault := &user_model.CreateUserOverwriteOptions{ overwriteDefault := &user_model.CreateUserOverwriteOptions{
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
} }
if err := user_model.CreateUser(ctx, user, overwriteDefault); err != nil { if err := user_model.CreateUser(ctx, user, overwriteDefault); err != nil {

View File

@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
gitea_context "code.gitea.io/gitea/modules/context" gitea_context "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/modules/web/middleware"
@ -172,8 +173,8 @@ func (s *SSPI) newUser(ctx context.Context, username string, cfg *sspi.Source) (
} }
emailNotificationPreference := user_model.EmailNotificationsDisabled emailNotificationPreference := user_model.EmailNotificationsDisabled
overwriteDefault := &user_model.CreateUserOverwriteOptions{ overwriteDefault := &user_model.CreateUserOverwriteOptions{
IsActive: util.OptionalBoolOf(cfg.AutoActivateUsers), IsActive: optional.Some(cfg.AutoActivateUsers),
KeepEmailPrivate: util.OptionalBoolTrue, KeepEmailPrivate: optional.Some(true),
EmailNotificationsPreference: &emailNotificationPreference, EmailNotificationsPreference: &emailNotificationPreference,
} }
if err := user_model.CreateUser(ctx, user, overwriteDefault); err != nil { if err := user_model.CreateUser(ctx, user, overwriteDefault); err != nil {

View File

@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -154,7 +155,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
ListAll: true, ListAll: true,
}, },
IsDeletedBranch: util.OptionalBoolFalse, IsDeletedBranch: optional.Some(false),
}) })
found := false found := false

View File

@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/queue"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
@ -61,7 +62,7 @@ func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git
branchOpts := git_model.FindBranchOptions{ branchOpts := git_model.FindBranchOptions{
RepoID: repo.ID, RepoID: repo.ID,
IsDeletedBranch: isDeletedBranch, IsDeletedBranch: isDeletedBranch.ToGeneric(),
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
Page: page, Page: page,
PageSize: pageSize, PageSize: pageSize,
@ -239,7 +240,7 @@ func syncBranchToDB(ctx context.Context, repoID, pusherID int64, branchName stri
// we cannot simply insert the branch but need to check we have branches or not // we cannot simply insert the branch but need to check we have branches or not
hasBranch, err := db.Exist[git_model.Branch](ctx, git_model.FindBranchOptions{ hasBranch, err := db.Exist[git_model.Branch](ctx, git_model.FindBranchOptions{
RepoID: repoID, RepoID: repoID,
IsDeletedBranch: util.OptionalBoolFalse, IsDeletedBranch: optional.Some(false),
}.ToConds()) }.ToConds())
if err != nil { if err != nil {
return err return err