Retroactively fix some SQL schema problems
I originally wasn't going to do passwords, but after struggling with webauthn I decided I'd just go for it. It simplifies the code a lot if I assert that I always have a password, displayname, etc.
This commit is contained in:
parent
981f043b7f
commit
4d55a391c9
12 changed files with 179 additions and 243 deletions
42
auth.go
42
auth.go
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/aarondl/opt/omit"
|
"github.com/aarondl/opt/omit"
|
||||||
"github.com/aarondl/opt/omitnull"
|
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/enums"
|
"github.com/Gleipnir-Technology/nidus-sync/enums"
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/models"
|
"github.com/Gleipnir-Technology/nidus-sync/models"
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/sql"
|
"github.com/Gleipnir-Technology/nidus-sync/sql"
|
||||||
|
|
@ -37,16 +36,18 @@ func addUserSession(r *http.Request, user *models.User) {
|
||||||
func getAuthenticatedUser(r *http.Request) (*models.User, error) {
|
func getAuthenticatedUser(r *http.Request) (*models.User, error) {
|
||||||
//user_id := sessionManager.GetInt(r.Context(), "user_id")
|
//user_id := sessionManager.GetInt(r.Context(), "user_id")
|
||||||
user_id_str := sessionManager.GetString(r.Context(), "user_id")
|
user_id_str := sessionManager.GetString(r.Context(), "user_id")
|
||||||
user_id, err := strconv.Atoi(user_id_str)
|
if user_id_str != "" {
|
||||||
if err != nil {
|
user_id, err := strconv.Atoi(user_id_str)
|
||||||
return nil, fmt.Errorf("Failed to convert user_id to int: %v", err)
|
if err != nil {
|
||||||
}
|
return nil, fmt.Errorf("Failed to convert user_id to int: %v", err)
|
||||||
username := sessionManager.GetString(r.Context(), "username")
|
}
|
||||||
slog.Info("Current session info",
|
username := sessionManager.GetString(r.Context(), "username")
|
||||||
slog.Int("user_id", user_id),
|
slog.Info("Current session info",
|
||||||
slog.String("username", username))
|
slog.Int("user_id", user_id),
|
||||||
if user_id > 0 && username != "" {
|
slog.String("username", username))
|
||||||
return models.FindUser(r.Context(), PGInstance.BobDB, int32(user_id))
|
if user_id > 0 && username != "" {
|
||||||
|
return models.FindUser(r.Context(), PGInstance.BobDB, int32(user_id))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// If we can't get the user from the session try to get from auth headers
|
// If we can't get the user from the session try to get from auth headers
|
||||||
username, password, ok := r.BasicAuth()
|
username, password, ok := r.BasicAuth()
|
||||||
|
|
@ -84,9 +85,9 @@ func signupUser(username string, name string, password string) (*models.User, er
|
||||||
return nil, fmt.Errorf("Cannot signup user: %v", err)
|
return nil, fmt.Errorf("Cannot signup user: %v", err)
|
||||||
}
|
}
|
||||||
setter := models.UserSetter{
|
setter := models.UserSetter{
|
||||||
DisplayName: omitnull.From(name),
|
DisplayName: omit.From(name),
|
||||||
PasswordHash: omitnull.From(passwordHash),
|
PasswordHash: omit.From(passwordHash),
|
||||||
PasswordHashType: omitnull.From(enums.HashtypeBcrypt14),
|
PasswordHashType: omit.From(enums.HashtypeBcrypt14),
|
||||||
Username: omit.From(username),
|
Username: omit.From(username),
|
||||||
}
|
}
|
||||||
u, err := models.Users.Insert(&setter).One(context.TODO(), PGInstance.BobDB)
|
u, err := models.Users.Insert(&setter).One(context.TODO(), PGInstance.BobDB)
|
||||||
|
|
@ -123,18 +124,7 @@ func validateUser(ctx context.Context, username string, password string) (*model
|
||||||
return nil, InvalidUsername{}
|
return nil, InvalidUsername{}
|
||||||
case 1:
|
case 1:
|
||||||
row := result[0]
|
row := result[0]
|
||||||
hash, err := row.PasswordHash.Value()
|
if !validatePassword(password, row.PasswordHash) {
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if hash == nil {
|
|
||||||
return nil, errors.New("Hash is nil")
|
|
||||||
}
|
|
||||||
hashStr, ok := hash.(string);
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("Hash isn't a string")
|
|
||||||
}
|
|
||||||
if !validatePassword(password, hashStr) {
|
|
||||||
return nil, InvalidCredentials{}
|
return nil, InvalidCredentials{}
|
||||||
}
|
}
|
||||||
user := models.User{
|
user := models.User{
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ var Users = Table[
|
||||||
},
|
},
|
||||||
ArcgisLicense: column{
|
ArcgisLicense: column{
|
||||||
Name: "arcgis_license",
|
Name: "arcgis_license",
|
||||||
DBType: "public.arcgis_license_type",
|
DBType: "public.arcgislicensetype",
|
||||||
Default: "NULL",
|
Default: "NULL",
|
||||||
Comment: "",
|
Comment: "",
|
||||||
Nullable: true,
|
Nullable: true,
|
||||||
|
|
@ -72,9 +72,9 @@ var Users = Table[
|
||||||
DisplayName: column{
|
DisplayName: column{
|
||||||
Name: "display_name",
|
Name: "display_name",
|
||||||
DBType: "character varying",
|
DBType: "character varying",
|
||||||
Default: "NULL",
|
Default: "",
|
||||||
Comment: "",
|
Comment: "",
|
||||||
Nullable: true,
|
Nullable: false,
|
||||||
Generated: false,
|
Generated: false,
|
||||||
AutoIncr: false,
|
AutoIncr: false,
|
||||||
},
|
},
|
||||||
|
|
@ -108,18 +108,18 @@ var Users = Table[
|
||||||
PasswordHashType: column{
|
PasswordHashType: column{
|
||||||
Name: "password_hash_type",
|
Name: "password_hash_type",
|
||||||
DBType: "public.hashtype",
|
DBType: "public.hashtype",
|
||||||
Default: "NULL",
|
Default: "",
|
||||||
Comment: "",
|
Comment: "",
|
||||||
Nullable: true,
|
Nullable: false,
|
||||||
Generated: false,
|
Generated: false,
|
||||||
AutoIncr: false,
|
AutoIncr: false,
|
||||||
},
|
},
|
||||||
PasswordHash: column{
|
PasswordHash: column{
|
||||||
Name: "password_hash",
|
Name: "password_hash",
|
||||||
DBType: "text",
|
DBType: "text",
|
||||||
Default: "NULL",
|
Default: "",
|
||||||
Comment: "",
|
Comment: "",
|
||||||
Nullable: true,
|
Nullable: false,
|
||||||
Generated: false,
|
Generated: false,
|
||||||
AutoIncr: false,
|
AutoIncr: false,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -8,65 +8,65 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Enum values for ArcgisLicenseType
|
// Enum values for Arcgislicensetype
|
||||||
const (
|
const (
|
||||||
ArcgisLicenseTypeAdvancedut ArcgisLicenseType = "advancedUT"
|
ArcgislicensetypeAdvancedut Arcgislicensetype = "advancedUT"
|
||||||
ArcgisLicenseTypeBasicut ArcgisLicenseType = "basicUT"
|
ArcgislicensetypeBasicut Arcgislicensetype = "basicUT"
|
||||||
ArcgisLicenseTypeCreatorut ArcgisLicenseType = "creatorUT"
|
ArcgislicensetypeCreatorut Arcgislicensetype = "creatorUT"
|
||||||
ArcgisLicenseTypeEditorut ArcgisLicenseType = "editorUT"
|
ArcgislicensetypeEditorut Arcgislicensetype = "editorUT"
|
||||||
ArcgisLicenseTypeFieldworkerut ArcgisLicenseType = "fieldWorkerUT"
|
ArcgislicensetypeFieldworkerut Arcgislicensetype = "fieldWorkerUT"
|
||||||
ArcgisLicenseTypeGisprofessionaladvut ArcgisLicenseType = "GISProfessionalAdvUT"
|
ArcgislicensetypeGisprofessionaladvut Arcgislicensetype = "GISProfessionalAdvUT"
|
||||||
ArcgisLicenseTypeGisprofessionalbasicut ArcgisLicenseType = "GISProfessionalBasicUT"
|
ArcgislicensetypeGisprofessionalbasicut Arcgislicensetype = "GISProfessionalBasicUT"
|
||||||
ArcgisLicenseTypeGisprofessionalstdut ArcgisLicenseType = "GISProfessionalStdUT"
|
ArcgislicensetypeGisprofessionalstdut Arcgislicensetype = "GISProfessionalStdUT"
|
||||||
ArcgisLicenseTypeIndoorsuserut ArcgisLicenseType = "IndoorsUserUT"
|
ArcgislicensetypeIndoorsuserut Arcgislicensetype = "IndoorsUserUT"
|
||||||
ArcgisLicenseTypeInsightsanalystut ArcgisLicenseType = "insightsAnalystUT"
|
ArcgislicensetypeInsightsanalystut Arcgislicensetype = "insightsAnalystUT"
|
||||||
ArcgisLicenseTypeLiteut ArcgisLicenseType = "liteUT"
|
ArcgislicensetypeLiteut Arcgislicensetype = "liteUT"
|
||||||
ArcgisLicenseTypeStandardut ArcgisLicenseType = "standardUT"
|
ArcgislicensetypeStandardut Arcgislicensetype = "standardUT"
|
||||||
ArcgisLicenseTypeStorytellerut ArcgisLicenseType = "storytellerUT"
|
ArcgislicensetypeStorytellerut Arcgislicensetype = "storytellerUT"
|
||||||
ArcgisLicenseTypeViewerut ArcgisLicenseType = "viewerUT"
|
ArcgislicensetypeViewerut Arcgislicensetype = "viewerUT"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AllArcgisLicenseType() []ArcgisLicenseType {
|
func AllArcgislicensetype() []Arcgislicensetype {
|
||||||
return []ArcgisLicenseType{
|
return []Arcgislicensetype{
|
||||||
ArcgisLicenseTypeAdvancedut,
|
ArcgislicensetypeAdvancedut,
|
||||||
ArcgisLicenseTypeBasicut,
|
ArcgislicensetypeBasicut,
|
||||||
ArcgisLicenseTypeCreatorut,
|
ArcgislicensetypeCreatorut,
|
||||||
ArcgisLicenseTypeEditorut,
|
ArcgislicensetypeEditorut,
|
||||||
ArcgisLicenseTypeFieldworkerut,
|
ArcgislicensetypeFieldworkerut,
|
||||||
ArcgisLicenseTypeGisprofessionaladvut,
|
ArcgislicensetypeGisprofessionaladvut,
|
||||||
ArcgisLicenseTypeGisprofessionalbasicut,
|
ArcgislicensetypeGisprofessionalbasicut,
|
||||||
ArcgisLicenseTypeGisprofessionalstdut,
|
ArcgislicensetypeGisprofessionalstdut,
|
||||||
ArcgisLicenseTypeIndoorsuserut,
|
ArcgislicensetypeIndoorsuserut,
|
||||||
ArcgisLicenseTypeInsightsanalystut,
|
ArcgislicensetypeInsightsanalystut,
|
||||||
ArcgisLicenseTypeLiteut,
|
ArcgislicensetypeLiteut,
|
||||||
ArcgisLicenseTypeStandardut,
|
ArcgislicensetypeStandardut,
|
||||||
ArcgisLicenseTypeStorytellerut,
|
ArcgislicensetypeStorytellerut,
|
||||||
ArcgisLicenseTypeViewerut,
|
ArcgislicensetypeViewerut,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArcgisLicenseType string
|
type Arcgislicensetype string
|
||||||
|
|
||||||
func (e ArcgisLicenseType) String() string {
|
func (e Arcgislicensetype) String() string {
|
||||||
return string(e)
|
return string(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ArcgisLicenseType) Valid() bool {
|
func (e Arcgislicensetype) Valid() bool {
|
||||||
switch e {
|
switch e {
|
||||||
case ArcgisLicenseTypeAdvancedut,
|
case ArcgislicensetypeAdvancedut,
|
||||||
ArcgisLicenseTypeBasicut,
|
ArcgislicensetypeBasicut,
|
||||||
ArcgisLicenseTypeCreatorut,
|
ArcgislicensetypeCreatorut,
|
||||||
ArcgisLicenseTypeEditorut,
|
ArcgislicensetypeEditorut,
|
||||||
ArcgisLicenseTypeFieldworkerut,
|
ArcgislicensetypeFieldworkerut,
|
||||||
ArcgisLicenseTypeGisprofessionaladvut,
|
ArcgislicensetypeGisprofessionaladvut,
|
||||||
ArcgisLicenseTypeGisprofessionalbasicut,
|
ArcgislicensetypeGisprofessionalbasicut,
|
||||||
ArcgisLicenseTypeGisprofessionalstdut,
|
ArcgislicensetypeGisprofessionalstdut,
|
||||||
ArcgisLicenseTypeIndoorsuserut,
|
ArcgislicensetypeIndoorsuserut,
|
||||||
ArcgisLicenseTypeInsightsanalystut,
|
ArcgislicensetypeInsightsanalystut,
|
||||||
ArcgisLicenseTypeLiteut,
|
ArcgislicensetypeLiteut,
|
||||||
ArcgisLicenseTypeStandardut,
|
ArcgislicensetypeStandardut,
|
||||||
ArcgisLicenseTypeStorytellerut,
|
ArcgislicensetypeStorytellerut,
|
||||||
ArcgisLicenseTypeViewerut:
|
ArcgislicensetypeViewerut:
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
|
|
@ -74,44 +74,44 @@ func (e ArcgisLicenseType) Valid() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// useful when testing in other packages
|
// useful when testing in other packages
|
||||||
func (e ArcgisLicenseType) All() []ArcgisLicenseType {
|
func (e Arcgislicensetype) All() []Arcgislicensetype {
|
||||||
return AllArcgisLicenseType()
|
return AllArcgislicensetype()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ArcgisLicenseType) MarshalText() ([]byte, error) {
|
func (e Arcgislicensetype) MarshalText() ([]byte, error) {
|
||||||
return []byte(e), nil
|
return []byte(e), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ArcgisLicenseType) UnmarshalText(text []byte) error {
|
func (e *Arcgislicensetype) UnmarshalText(text []byte) error {
|
||||||
return e.Scan(text)
|
return e.Scan(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ArcgisLicenseType) MarshalBinary() ([]byte, error) {
|
func (e Arcgislicensetype) MarshalBinary() ([]byte, error) {
|
||||||
return []byte(e), nil
|
return []byte(e), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ArcgisLicenseType) UnmarshalBinary(data []byte) error {
|
func (e *Arcgislicensetype) UnmarshalBinary(data []byte) error {
|
||||||
return e.Scan(data)
|
return e.Scan(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ArcgisLicenseType) Value() (driver.Value, error) {
|
func (e Arcgislicensetype) Value() (driver.Value, error) {
|
||||||
return string(e), nil
|
return string(e), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ArcgisLicenseType) Scan(value any) error {
|
func (e *Arcgislicensetype) Scan(value any) error {
|
||||||
switch x := value.(type) {
|
switch x := value.(type) {
|
||||||
case string:
|
case string:
|
||||||
*e = ArcgisLicenseType(x)
|
*e = Arcgislicensetype(x)
|
||||||
case []byte:
|
case []byte:
|
||||||
*e = ArcgisLicenseType(x)
|
*e = Arcgislicensetype(x)
|
||||||
case nil:
|
case nil:
|
||||||
return fmt.Errorf("cannot nil into ArcgisLicenseType")
|
return fmt.Errorf("cannot nil into Arcgislicensetype")
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("cannot scan type %T: %v", value, value)
|
return fmt.Errorf("cannot scan type %T: %v", value, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !e.Valid() {
|
if !e.Valid() {
|
||||||
return fmt.Errorf("invalid ArcgisLicenseType value: %s", *e)
|
return fmt.Errorf("invalid Arcgislicensetype value: %s", *e)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -127,16 +127,16 @@ func (f *Factory) FromExistingUser(m *models.User) *UserTemplate {
|
||||||
|
|
||||||
o.ID = func() int32 { return m.ID }
|
o.ID = func() int32 { return m.ID }
|
||||||
o.ArcgisAccessToken = func() null.Val[string] { return m.ArcgisAccessToken }
|
o.ArcgisAccessToken = func() null.Val[string] { return m.ArcgisAccessToken }
|
||||||
o.ArcgisLicense = func() null.Val[enums.ArcgisLicenseType] { return m.ArcgisLicense }
|
o.ArcgisLicense = func() null.Val[enums.Arcgislicensetype] { return m.ArcgisLicense }
|
||||||
o.ArcgisRefreshToken = func() null.Val[string] { return m.ArcgisRefreshToken }
|
o.ArcgisRefreshToken = func() null.Val[string] { return m.ArcgisRefreshToken }
|
||||||
o.ArcgisRefreshTokenExpires = func() null.Val[time.Time] { return m.ArcgisRefreshTokenExpires }
|
o.ArcgisRefreshTokenExpires = func() null.Val[time.Time] { return m.ArcgisRefreshTokenExpires }
|
||||||
o.ArcgisRole = func() null.Val[string] { return m.ArcgisRole }
|
o.ArcgisRole = func() null.Val[string] { return m.ArcgisRole }
|
||||||
o.DisplayName = func() null.Val[string] { return m.DisplayName }
|
o.DisplayName = func() string { return m.DisplayName }
|
||||||
o.Email = func() null.Val[string] { return m.Email }
|
o.Email = func() null.Val[string] { return m.Email }
|
||||||
o.OrganizationID = func() null.Val[int32] { return m.OrganizationID }
|
o.OrganizationID = func() null.Val[int32] { return m.OrganizationID }
|
||||||
o.Username = func() string { return m.Username }
|
o.Username = func() string { return m.Username }
|
||||||
o.PasswordHashType = func() null.Val[enums.Hashtype] { return m.PasswordHashType }
|
o.PasswordHashType = func() enums.Hashtype { return m.PasswordHashType }
|
||||||
o.PasswordHash = func() null.Val[string] { return m.PasswordHash }
|
o.PasswordHash = func() string { return m.PasswordHash }
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
if m.R.Organization != nil {
|
if m.R.Organization != nil {
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,12 @@ func random_bool(f *faker.Faker, limits ...string) bool {
|
||||||
return f.Bool()
|
return f.Bool()
|
||||||
}
|
}
|
||||||
|
|
||||||
func random_enums_ArcgisLicenseType(f *faker.Faker, limits ...string) enums.ArcgisLicenseType {
|
func random_enums_Arcgislicensetype(f *faker.Faker, limits ...string) enums.Arcgislicensetype {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
f = &defaultFaker
|
f = &defaultFaker
|
||||||
}
|
}
|
||||||
|
|
||||||
var e enums.ArcgisLicenseType
|
var e enums.Arcgislicensetype
|
||||||
all := e.All()
|
all := e.All()
|
||||||
return all[f.IntBetween(0, len(all)-1)]
|
return all[f.IntBetween(0, len(all)-1)]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,16 +40,16 @@ func (mods UserModSlice) Apply(ctx context.Context, n *UserTemplate) {
|
||||||
type UserTemplate struct {
|
type UserTemplate struct {
|
||||||
ID func() int32
|
ID func() int32
|
||||||
ArcgisAccessToken func() null.Val[string]
|
ArcgisAccessToken func() null.Val[string]
|
||||||
ArcgisLicense func() null.Val[enums.ArcgisLicenseType]
|
ArcgisLicense func() null.Val[enums.Arcgislicensetype]
|
||||||
ArcgisRefreshToken func() null.Val[string]
|
ArcgisRefreshToken func() null.Val[string]
|
||||||
ArcgisRefreshTokenExpires func() null.Val[time.Time]
|
ArcgisRefreshTokenExpires func() null.Val[time.Time]
|
||||||
ArcgisRole func() null.Val[string]
|
ArcgisRole func() null.Val[string]
|
||||||
DisplayName func() null.Val[string]
|
DisplayName func() string
|
||||||
Email func() null.Val[string]
|
Email func() null.Val[string]
|
||||||
OrganizationID func() null.Val[int32]
|
OrganizationID func() null.Val[int32]
|
||||||
Username func() string
|
Username func() string
|
||||||
PasswordHashType func() null.Val[enums.Hashtype]
|
PasswordHashType func() enums.Hashtype
|
||||||
PasswordHash func() null.Val[string]
|
PasswordHash func() string
|
||||||
|
|
||||||
r userR
|
r userR
|
||||||
f *Factory
|
f *Factory
|
||||||
|
|
@ -114,7 +114,7 @@ func (o UserTemplate) BuildSetter() *models.UserSetter {
|
||||||
}
|
}
|
||||||
if o.DisplayName != nil {
|
if o.DisplayName != nil {
|
||||||
val := o.DisplayName()
|
val := o.DisplayName()
|
||||||
m.DisplayName = omitnull.FromNull(val)
|
m.DisplayName = omit.From(val)
|
||||||
}
|
}
|
||||||
if o.Email != nil {
|
if o.Email != nil {
|
||||||
val := o.Email()
|
val := o.Email()
|
||||||
|
|
@ -130,11 +130,11 @@ func (o UserTemplate) BuildSetter() *models.UserSetter {
|
||||||
}
|
}
|
||||||
if o.PasswordHashType != nil {
|
if o.PasswordHashType != nil {
|
||||||
val := o.PasswordHashType()
|
val := o.PasswordHashType()
|
||||||
m.PasswordHashType = omitnull.FromNull(val)
|
m.PasswordHashType = omit.From(val)
|
||||||
}
|
}
|
||||||
if o.PasswordHash != nil {
|
if o.PasswordHash != nil {
|
||||||
val := o.PasswordHash()
|
val := o.PasswordHash()
|
||||||
m.PasswordHash = omitnull.FromNull(val)
|
m.PasswordHash = omit.From(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
@ -214,10 +214,22 @@ func (o UserTemplate) BuildMany(number int) models.UserSlice {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureCreatableUser(m *models.UserSetter) {
|
func ensureCreatableUser(m *models.UserSetter) {
|
||||||
|
if !(m.DisplayName.IsValue()) {
|
||||||
|
val := random_string(nil, "200")
|
||||||
|
m.DisplayName = omit.From(val)
|
||||||
|
}
|
||||||
if !(m.Username.IsValue()) {
|
if !(m.Username.IsValue()) {
|
||||||
val := random_string(nil)
|
val := random_string(nil)
|
||||||
m.Username = omit.From(val)
|
m.Username = omit.From(val)
|
||||||
}
|
}
|
||||||
|
if !(m.PasswordHashType.IsValue()) {
|
||||||
|
val := random_enums_Hashtype(nil)
|
||||||
|
m.PasswordHashType = omit.From(val)
|
||||||
|
}
|
||||||
|
if !(m.PasswordHash.IsValue()) {
|
||||||
|
val := random_string(nil)
|
||||||
|
m.PasswordHash = omit.From(val)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// insertOptRels creates and inserts any optional the relationships on *models.User
|
// insertOptRels creates and inserts any optional the relationships on *models.User
|
||||||
|
|
@ -437,14 +449,14 @@ func (m userMods) RandomArcgisAccessTokenNotNull(f *faker.Faker) UserMod {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the model columns to this value
|
// Set the model columns to this value
|
||||||
func (m userMods) ArcgisLicense(val null.Val[enums.ArcgisLicenseType]) UserMod {
|
func (m userMods) ArcgisLicense(val null.Val[enums.Arcgislicensetype]) UserMod {
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||||
o.ArcgisLicense = func() null.Val[enums.ArcgisLicenseType] { return val }
|
o.ArcgisLicense = func() null.Val[enums.Arcgislicensetype] { return val }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the Column from the function
|
// Set the Column from the function
|
||||||
func (m userMods) ArcgisLicenseFunc(f func() null.Val[enums.ArcgisLicenseType]) UserMod {
|
func (m userMods) ArcgisLicenseFunc(f func() null.Val[enums.Arcgislicensetype]) UserMod {
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||||
o.ArcgisLicense = f
|
o.ArcgisLicense = f
|
||||||
})
|
})
|
||||||
|
|
@ -462,12 +474,12 @@ func (m userMods) UnsetArcgisLicense() UserMod {
|
||||||
// The generated value is sometimes null
|
// The generated value is sometimes null
|
||||||
func (m userMods) RandomArcgisLicense(f *faker.Faker) UserMod {
|
func (m userMods) RandomArcgisLicense(f *faker.Faker) UserMod {
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||||
o.ArcgisLicense = func() null.Val[enums.ArcgisLicenseType] {
|
o.ArcgisLicense = func() null.Val[enums.Arcgislicensetype] {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
f = &defaultFaker
|
f = &defaultFaker
|
||||||
}
|
}
|
||||||
|
|
||||||
val := random_enums_ArcgisLicenseType(f)
|
val := random_enums_Arcgislicensetype(f)
|
||||||
return null.From(val)
|
return null.From(val)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -478,12 +490,12 @@ func (m userMods) RandomArcgisLicense(f *faker.Faker) UserMod {
|
||||||
// The generated value is never null
|
// The generated value is never null
|
||||||
func (m userMods) RandomArcgisLicenseNotNull(f *faker.Faker) UserMod {
|
func (m userMods) RandomArcgisLicenseNotNull(f *faker.Faker) UserMod {
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||||
o.ArcgisLicense = func() null.Val[enums.ArcgisLicenseType] {
|
o.ArcgisLicense = func() null.Val[enums.Arcgislicensetype] {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
f = &defaultFaker
|
f = &defaultFaker
|
||||||
}
|
}
|
||||||
|
|
||||||
val := random_enums_ArcgisLicenseType(f)
|
val := random_enums_Arcgislicensetype(f)
|
||||||
return null.From(val)
|
return null.From(val)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -649,14 +661,14 @@ func (m userMods) RandomArcgisRoleNotNull(f *faker.Faker) UserMod {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the model columns to this value
|
// Set the model columns to this value
|
||||||
func (m userMods) DisplayName(val null.Val[string]) UserMod {
|
func (m userMods) DisplayName(val string) UserMod {
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||||
o.DisplayName = func() null.Val[string] { return val }
|
o.DisplayName = func() string { return val }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the Column from the function
|
// Set the Column from the function
|
||||||
func (m userMods) DisplayNameFunc(f func() null.Val[string]) UserMod {
|
func (m userMods) DisplayNameFunc(f func() string) UserMod {
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||||
o.DisplayName = f
|
o.DisplayName = f
|
||||||
})
|
})
|
||||||
|
|
@ -671,32 +683,10 @@ func (m userMods) UnsetDisplayName() UserMod {
|
||||||
|
|
||||||
// Generates a random value for the column using the given faker
|
// Generates a random value for the column using the given faker
|
||||||
// if faker is nil, a default faker is used
|
// if faker is nil, a default faker is used
|
||||||
// The generated value is sometimes null
|
|
||||||
func (m userMods) RandomDisplayName(f *faker.Faker) UserMod {
|
func (m userMods) RandomDisplayName(f *faker.Faker) UserMod {
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||||
o.DisplayName = func() null.Val[string] {
|
o.DisplayName = func() string {
|
||||||
if f == nil {
|
return random_string(f, "200")
|
||||||
f = &defaultFaker
|
|
||||||
}
|
|
||||||
|
|
||||||
val := random_string(f, "200")
|
|
||||||
return null.From(val)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generates a random value for the column using the given faker
|
|
||||||
// if faker is nil, a default faker is used
|
|
||||||
// The generated value is never null
|
|
||||||
func (m userMods) RandomDisplayNameNotNull(f *faker.Faker) UserMod {
|
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
|
||||||
o.DisplayName = func() null.Val[string] {
|
|
||||||
if f == nil {
|
|
||||||
f = &defaultFaker
|
|
||||||
}
|
|
||||||
|
|
||||||
val := random_string(f, "200")
|
|
||||||
return null.From(val)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -839,14 +829,14 @@ func (m userMods) RandomUsername(f *faker.Faker) UserMod {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the model columns to this value
|
// Set the model columns to this value
|
||||||
func (m userMods) PasswordHashType(val null.Val[enums.Hashtype]) UserMod {
|
func (m userMods) PasswordHashType(val enums.Hashtype) UserMod {
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||||
o.PasswordHashType = func() null.Val[enums.Hashtype] { return val }
|
o.PasswordHashType = func() enums.Hashtype { return val }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the Column from the function
|
// Set the Column from the function
|
||||||
func (m userMods) PasswordHashTypeFunc(f func() null.Val[enums.Hashtype]) UserMod {
|
func (m userMods) PasswordHashTypeFunc(f func() enums.Hashtype) UserMod {
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||||
o.PasswordHashType = f
|
o.PasswordHashType = f
|
||||||
})
|
})
|
||||||
|
|
@ -861,45 +851,23 @@ func (m userMods) UnsetPasswordHashType() UserMod {
|
||||||
|
|
||||||
// Generates a random value for the column using the given faker
|
// Generates a random value for the column using the given faker
|
||||||
// if faker is nil, a default faker is used
|
// if faker is nil, a default faker is used
|
||||||
// The generated value is sometimes null
|
|
||||||
func (m userMods) RandomPasswordHashType(f *faker.Faker) UserMod {
|
func (m userMods) RandomPasswordHashType(f *faker.Faker) UserMod {
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||||
o.PasswordHashType = func() null.Val[enums.Hashtype] {
|
o.PasswordHashType = func() enums.Hashtype {
|
||||||
if f == nil {
|
return random_enums_Hashtype(f)
|
||||||
f = &defaultFaker
|
|
||||||
}
|
|
||||||
|
|
||||||
val := random_enums_Hashtype(f)
|
|
||||||
return null.From(val)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generates a random value for the column using the given faker
|
|
||||||
// if faker is nil, a default faker is used
|
|
||||||
// The generated value is never null
|
|
||||||
func (m userMods) RandomPasswordHashTypeNotNull(f *faker.Faker) UserMod {
|
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
|
||||||
o.PasswordHashType = func() null.Val[enums.Hashtype] {
|
|
||||||
if f == nil {
|
|
||||||
f = &defaultFaker
|
|
||||||
}
|
|
||||||
|
|
||||||
val := random_enums_Hashtype(f)
|
|
||||||
return null.From(val)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the model columns to this value
|
// Set the model columns to this value
|
||||||
func (m userMods) PasswordHash(val null.Val[string]) UserMod {
|
func (m userMods) PasswordHash(val string) UserMod {
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||||
o.PasswordHash = func() null.Val[string] { return val }
|
o.PasswordHash = func() string { return val }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the Column from the function
|
// Set the Column from the function
|
||||||
func (m userMods) PasswordHashFunc(f func() null.Val[string]) UserMod {
|
func (m userMods) PasswordHashFunc(f func() string) UserMod {
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||||
o.PasswordHash = f
|
o.PasswordHash = f
|
||||||
})
|
})
|
||||||
|
|
@ -914,32 +882,10 @@ func (m userMods) UnsetPasswordHash() UserMod {
|
||||||
|
|
||||||
// Generates a random value for the column using the given faker
|
// Generates a random value for the column using the given faker
|
||||||
// if faker is nil, a default faker is used
|
// if faker is nil, a default faker is used
|
||||||
// The generated value is sometimes null
|
|
||||||
func (m userMods) RandomPasswordHash(f *faker.Faker) UserMod {
|
func (m userMods) RandomPasswordHash(f *faker.Faker) UserMod {
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||||
o.PasswordHash = func() null.Val[string] {
|
o.PasswordHash = func() string {
|
||||||
if f == nil {
|
return random_string(f)
|
||||||
f = &defaultFaker
|
|
||||||
}
|
|
||||||
|
|
||||||
val := random_string(f)
|
|
||||||
return null.From(val)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generates a random value for the column using the given faker
|
|
||||||
// if faker is nil, a default faker is used
|
|
||||||
// The generated value is never null
|
|
||||||
func (m userMods) RandomPasswordHashNotNull(f *faker.Faker) UserMod {
|
|
||||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
|
||||||
o.PasswordHash = func() null.Val[string] {
|
|
||||||
if f == nil {
|
|
||||||
f = &defaultFaker
|
|
||||||
}
|
|
||||||
|
|
||||||
val := random_string(f)
|
|
||||||
return null.From(val)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
-- +goose Up
|
-- +goose Up
|
||||||
CREATE TYPE arcgis_license_type AS ENUM (
|
CREATE TYPE ArcgisLicenseType AS ENUM (
|
||||||
'advancedUT',
|
'advancedUT',
|
||||||
'basicUT',
|
'basicUT',
|
||||||
'creatorUT',
|
'creatorUT',
|
||||||
|
|
@ -23,11 +23,11 @@ CREATE TABLE organization (
|
||||||
CREATE TABLE user_ (
|
CREATE TABLE user_ (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
arcgis_access_token TEXT,
|
arcgis_access_token TEXT,
|
||||||
arcgis_license arcgis_license_type,
|
arcgis_license ArcgisLicenseType,
|
||||||
arcgis_refresh_token TEXT,
|
arcgis_refresh_token TEXT,
|
||||||
arcgis_refresh_token_expires TIMESTAMP,
|
arcgis_refresh_token_expires TIMESTAMP,
|
||||||
arcgis_role TEXT,
|
arcgis_role TEXT,
|
||||||
display_name VARCHAR(200),
|
display_name VARCHAR(200) NOT NULL,
|
||||||
email TEXT,
|
email TEXT,
|
||||||
organization_id INTEGER REFERENCES organization (id),
|
organization_id INTEGER REFERENCES organization (id),
|
||||||
username TEXT NOT NULL
|
username TEXT NOT NULL
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
CREATE TYPE HashType AS ENUM (
|
CREATE TYPE HashType AS ENUM (
|
||||||
'bcrypt-14');
|
'bcrypt-14');
|
||||||
|
|
||||||
ALTER TABLE user_ ADD COLUMN password_hash_type HashType;
|
ALTER TABLE user_ ADD COLUMN password_hash_type HashType NOT NULL;
|
||||||
ALTER TABLE user_ ADD COLUMN password_hash TEXT;
|
ALTER TABLE user_ ADD COLUMN password_hash TEXT NOT NULL;
|
||||||
-- +goose Down
|
-- +goose Down
|
||||||
ALTER TABLE user_ DROP COLUMN password_hash;
|
ALTER TABLE user_ DROP COLUMN password_hash;
|
||||||
ALTER TABLE user_ DROP COLUMN password_hash_type;
|
ALTER TABLE user_ DROP COLUMN password_hash_type;
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,11 @@ var _ bob.HookableType = &Session{}
|
||||||
// Make sure the type User runs hooks after queries
|
// Make sure the type User runs hooks after queries
|
||||||
var _ bob.HookableType = &User{}
|
var _ bob.HookableType = &User{}
|
||||||
|
|
||||||
// Make sure the type enums.ArcgisLicenseType satisfies database/sql.Scanner
|
// Make sure the type enums.Arcgislicensetype satisfies database/sql.Scanner
|
||||||
var _ sql.Scanner = (*enums.ArcgisLicenseType)(nil)
|
var _ sql.Scanner = (*enums.Arcgislicensetype)(nil)
|
||||||
|
|
||||||
// Make sure the type enums.ArcgisLicenseType satisfies database/sql/driver.Valuer
|
// Make sure the type enums.Arcgislicensetype satisfies database/sql/driver.Valuer
|
||||||
var _ driver.Valuer = *new(enums.ArcgisLicenseType)
|
var _ driver.Valuer = *new(enums.Arcgislicensetype)
|
||||||
|
|
||||||
// Make sure the type enums.Hashtype satisfies database/sql.Scanner
|
// Make sure the type enums.Hashtype satisfies database/sql.Scanner
|
||||||
var _ sql.Scanner = (*enums.Hashtype)(nil)
|
var _ sql.Scanner = (*enums.Hashtype)(nil)
|
||||||
|
|
|
||||||
|
|
@ -29,16 +29,16 @@ import (
|
||||||
type User struct {
|
type User struct {
|
||||||
ID int32 `db:"id,pk" `
|
ID int32 `db:"id,pk" `
|
||||||
ArcgisAccessToken null.Val[string] `db:"arcgis_access_token" `
|
ArcgisAccessToken null.Val[string] `db:"arcgis_access_token" `
|
||||||
ArcgisLicense null.Val[enums.ArcgisLicenseType] `db:"arcgis_license" `
|
ArcgisLicense null.Val[enums.Arcgislicensetype] `db:"arcgis_license" `
|
||||||
ArcgisRefreshToken null.Val[string] `db:"arcgis_refresh_token" `
|
ArcgisRefreshToken null.Val[string] `db:"arcgis_refresh_token" `
|
||||||
ArcgisRefreshTokenExpires null.Val[time.Time] `db:"arcgis_refresh_token_expires" `
|
ArcgisRefreshTokenExpires null.Val[time.Time] `db:"arcgis_refresh_token_expires" `
|
||||||
ArcgisRole null.Val[string] `db:"arcgis_role" `
|
ArcgisRole null.Val[string] `db:"arcgis_role" `
|
||||||
DisplayName null.Val[string] `db:"display_name" `
|
DisplayName string `db:"display_name" `
|
||||||
Email null.Val[string] `db:"email" `
|
Email null.Val[string] `db:"email" `
|
||||||
OrganizationID null.Val[int32] `db:"organization_id" `
|
OrganizationID null.Val[int32] `db:"organization_id" `
|
||||||
Username string `db:"username" `
|
Username string `db:"username" `
|
||||||
PasswordHashType null.Val[enums.Hashtype] `db:"password_hash_type" `
|
PasswordHashType enums.Hashtype `db:"password_hash_type" `
|
||||||
PasswordHash null.Val[string] `db:"password_hash" `
|
PasswordHash string `db:"password_hash" `
|
||||||
|
|
||||||
R userR `db:"-" `
|
R userR `db:"-" `
|
||||||
}
|
}
|
||||||
|
|
@ -110,16 +110,16 @@ func (userColumns) AliasedAs(alias string) userColumns {
|
||||||
type UserSetter struct {
|
type UserSetter struct {
|
||||||
ID omit.Val[int32] `db:"id,pk" `
|
ID omit.Val[int32] `db:"id,pk" `
|
||||||
ArcgisAccessToken omitnull.Val[string] `db:"arcgis_access_token" `
|
ArcgisAccessToken omitnull.Val[string] `db:"arcgis_access_token" `
|
||||||
ArcgisLicense omitnull.Val[enums.ArcgisLicenseType] `db:"arcgis_license" `
|
ArcgisLicense omitnull.Val[enums.Arcgislicensetype] `db:"arcgis_license" `
|
||||||
ArcgisRefreshToken omitnull.Val[string] `db:"arcgis_refresh_token" `
|
ArcgisRefreshToken omitnull.Val[string] `db:"arcgis_refresh_token" `
|
||||||
ArcgisRefreshTokenExpires omitnull.Val[time.Time] `db:"arcgis_refresh_token_expires" `
|
ArcgisRefreshTokenExpires omitnull.Val[time.Time] `db:"arcgis_refresh_token_expires" `
|
||||||
ArcgisRole omitnull.Val[string] `db:"arcgis_role" `
|
ArcgisRole omitnull.Val[string] `db:"arcgis_role" `
|
||||||
DisplayName omitnull.Val[string] `db:"display_name" `
|
DisplayName omit.Val[string] `db:"display_name" `
|
||||||
Email omitnull.Val[string] `db:"email" `
|
Email omitnull.Val[string] `db:"email" `
|
||||||
OrganizationID omitnull.Val[int32] `db:"organization_id" `
|
OrganizationID omitnull.Val[int32] `db:"organization_id" `
|
||||||
Username omit.Val[string] `db:"username" `
|
Username omit.Val[string] `db:"username" `
|
||||||
PasswordHashType omitnull.Val[enums.Hashtype] `db:"password_hash_type" `
|
PasswordHashType omit.Val[enums.Hashtype] `db:"password_hash_type" `
|
||||||
PasswordHash omitnull.Val[string] `db:"password_hash" `
|
PasswordHash omit.Val[string] `db:"password_hash" `
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s UserSetter) SetColumns() []string {
|
func (s UserSetter) SetColumns() []string {
|
||||||
|
|
@ -142,7 +142,7 @@ func (s UserSetter) SetColumns() []string {
|
||||||
if !s.ArcgisRole.IsUnset() {
|
if !s.ArcgisRole.IsUnset() {
|
||||||
vals = append(vals, "arcgis_role")
|
vals = append(vals, "arcgis_role")
|
||||||
}
|
}
|
||||||
if !s.DisplayName.IsUnset() {
|
if s.DisplayName.IsValue() {
|
||||||
vals = append(vals, "display_name")
|
vals = append(vals, "display_name")
|
||||||
}
|
}
|
||||||
if !s.Email.IsUnset() {
|
if !s.Email.IsUnset() {
|
||||||
|
|
@ -154,10 +154,10 @@ func (s UserSetter) SetColumns() []string {
|
||||||
if s.Username.IsValue() {
|
if s.Username.IsValue() {
|
||||||
vals = append(vals, "username")
|
vals = append(vals, "username")
|
||||||
}
|
}
|
||||||
if !s.PasswordHashType.IsUnset() {
|
if s.PasswordHashType.IsValue() {
|
||||||
vals = append(vals, "password_hash_type")
|
vals = append(vals, "password_hash_type")
|
||||||
}
|
}
|
||||||
if !s.PasswordHash.IsUnset() {
|
if s.PasswordHash.IsValue() {
|
||||||
vals = append(vals, "password_hash")
|
vals = append(vals, "password_hash")
|
||||||
}
|
}
|
||||||
return vals
|
return vals
|
||||||
|
|
@ -182,8 +182,8 @@ func (s UserSetter) Overwrite(t *User) {
|
||||||
if !s.ArcgisRole.IsUnset() {
|
if !s.ArcgisRole.IsUnset() {
|
||||||
t.ArcgisRole = s.ArcgisRole.MustGetNull()
|
t.ArcgisRole = s.ArcgisRole.MustGetNull()
|
||||||
}
|
}
|
||||||
if !s.DisplayName.IsUnset() {
|
if s.DisplayName.IsValue() {
|
||||||
t.DisplayName = s.DisplayName.MustGetNull()
|
t.DisplayName = s.DisplayName.MustGet()
|
||||||
}
|
}
|
||||||
if !s.Email.IsUnset() {
|
if !s.Email.IsUnset() {
|
||||||
t.Email = s.Email.MustGetNull()
|
t.Email = s.Email.MustGetNull()
|
||||||
|
|
@ -194,11 +194,11 @@ func (s UserSetter) Overwrite(t *User) {
|
||||||
if s.Username.IsValue() {
|
if s.Username.IsValue() {
|
||||||
t.Username = s.Username.MustGet()
|
t.Username = s.Username.MustGet()
|
||||||
}
|
}
|
||||||
if !s.PasswordHashType.IsUnset() {
|
if s.PasswordHashType.IsValue() {
|
||||||
t.PasswordHashType = s.PasswordHashType.MustGetNull()
|
t.PasswordHashType = s.PasswordHashType.MustGet()
|
||||||
}
|
}
|
||||||
if !s.PasswordHash.IsUnset() {
|
if s.PasswordHash.IsValue() {
|
||||||
t.PasswordHash = s.PasswordHash.MustGetNull()
|
t.PasswordHash = s.PasswordHash.MustGet()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,8 +245,8 @@ func (s *UserSetter) Apply(q *dialect.InsertQuery) {
|
||||||
vals[5] = psql.Raw("DEFAULT")
|
vals[5] = psql.Raw("DEFAULT")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !s.DisplayName.IsUnset() {
|
if s.DisplayName.IsValue() {
|
||||||
vals[6] = psql.Arg(s.DisplayName.MustGetNull())
|
vals[6] = psql.Arg(s.DisplayName.MustGet())
|
||||||
} else {
|
} else {
|
||||||
vals[6] = psql.Raw("DEFAULT")
|
vals[6] = psql.Raw("DEFAULT")
|
||||||
}
|
}
|
||||||
|
|
@ -269,14 +269,14 @@ func (s *UserSetter) Apply(q *dialect.InsertQuery) {
|
||||||
vals[9] = psql.Raw("DEFAULT")
|
vals[9] = psql.Raw("DEFAULT")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !s.PasswordHashType.IsUnset() {
|
if s.PasswordHashType.IsValue() {
|
||||||
vals[10] = psql.Arg(s.PasswordHashType.MustGetNull())
|
vals[10] = psql.Arg(s.PasswordHashType.MustGet())
|
||||||
} else {
|
} else {
|
||||||
vals[10] = psql.Raw("DEFAULT")
|
vals[10] = psql.Raw("DEFAULT")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !s.PasswordHash.IsUnset() {
|
if s.PasswordHash.IsValue() {
|
||||||
vals[11] = psql.Arg(s.PasswordHash.MustGetNull())
|
vals[11] = psql.Arg(s.PasswordHash.MustGet())
|
||||||
} else {
|
} else {
|
||||||
vals[11] = psql.Raw("DEFAULT")
|
vals[11] = psql.Raw("DEFAULT")
|
||||||
}
|
}
|
||||||
|
|
@ -334,7 +334,7 @@ func (s UserSetter) Expressions(prefix ...string) []bob.Expression {
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !s.DisplayName.IsUnset() {
|
if s.DisplayName.IsValue() {
|
||||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||||
psql.Quote(append(prefix, "display_name")...),
|
psql.Quote(append(prefix, "display_name")...),
|
||||||
psql.Arg(s.DisplayName),
|
psql.Arg(s.DisplayName),
|
||||||
|
|
@ -362,14 +362,14 @@ func (s UserSetter) Expressions(prefix ...string) []bob.Expression {
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !s.PasswordHashType.IsUnset() {
|
if s.PasswordHashType.IsValue() {
|
||||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||||
psql.Quote(append(prefix, "password_hash_type")...),
|
psql.Quote(append(prefix, "password_hash_type")...),
|
||||||
psql.Arg(s.PasswordHashType),
|
psql.Arg(s.PasswordHashType),
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !s.PasswordHash.IsUnset() {
|
if s.PasswordHash.IsValue() {
|
||||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||||
psql.Quote(append(prefix, "password_hash")...),
|
psql.Quote(append(prefix, "password_hash")...),
|
||||||
psql.Arg(s.PasswordHash),
|
psql.Arg(s.PasswordHash),
|
||||||
|
|
@ -677,16 +677,16 @@ func (user0 *User) AttachOrganization(ctx context.Context, exec bob.Executor, or
|
||||||
type userWhere[Q psql.Filterable] struct {
|
type userWhere[Q psql.Filterable] struct {
|
||||||
ID psql.WhereMod[Q, int32]
|
ID psql.WhereMod[Q, int32]
|
||||||
ArcgisAccessToken psql.WhereNullMod[Q, string]
|
ArcgisAccessToken psql.WhereNullMod[Q, string]
|
||||||
ArcgisLicense psql.WhereNullMod[Q, enums.ArcgisLicenseType]
|
ArcgisLicense psql.WhereNullMod[Q, enums.Arcgislicensetype]
|
||||||
ArcgisRefreshToken psql.WhereNullMod[Q, string]
|
ArcgisRefreshToken psql.WhereNullMod[Q, string]
|
||||||
ArcgisRefreshTokenExpires psql.WhereNullMod[Q, time.Time]
|
ArcgisRefreshTokenExpires psql.WhereNullMod[Q, time.Time]
|
||||||
ArcgisRole psql.WhereNullMod[Q, string]
|
ArcgisRole psql.WhereNullMod[Q, string]
|
||||||
DisplayName psql.WhereNullMod[Q, string]
|
DisplayName psql.WhereMod[Q, string]
|
||||||
Email psql.WhereNullMod[Q, string]
|
Email psql.WhereNullMod[Q, string]
|
||||||
OrganizationID psql.WhereNullMod[Q, int32]
|
OrganizationID psql.WhereNullMod[Q, int32]
|
||||||
Username psql.WhereMod[Q, string]
|
Username psql.WhereMod[Q, string]
|
||||||
PasswordHashType psql.WhereNullMod[Q, enums.Hashtype]
|
PasswordHashType psql.WhereMod[Q, enums.Hashtype]
|
||||||
PasswordHash psql.WhereNullMod[Q, string]
|
PasswordHash psql.WhereMod[Q, string]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (userWhere[Q]) AliasedAs(alias string) userWhere[Q] {
|
func (userWhere[Q]) AliasedAs(alias string) userWhere[Q] {
|
||||||
|
|
@ -697,16 +697,16 @@ func buildUserWhere[Q psql.Filterable](cols userColumns) userWhere[Q] {
|
||||||
return userWhere[Q]{
|
return userWhere[Q]{
|
||||||
ID: psql.Where[Q, int32](cols.ID),
|
ID: psql.Where[Q, int32](cols.ID),
|
||||||
ArcgisAccessToken: psql.WhereNull[Q, string](cols.ArcgisAccessToken),
|
ArcgisAccessToken: psql.WhereNull[Q, string](cols.ArcgisAccessToken),
|
||||||
ArcgisLicense: psql.WhereNull[Q, enums.ArcgisLicenseType](cols.ArcgisLicense),
|
ArcgisLicense: psql.WhereNull[Q, enums.Arcgislicensetype](cols.ArcgisLicense),
|
||||||
ArcgisRefreshToken: psql.WhereNull[Q, string](cols.ArcgisRefreshToken),
|
ArcgisRefreshToken: psql.WhereNull[Q, string](cols.ArcgisRefreshToken),
|
||||||
ArcgisRefreshTokenExpires: psql.WhereNull[Q, time.Time](cols.ArcgisRefreshTokenExpires),
|
ArcgisRefreshTokenExpires: psql.WhereNull[Q, time.Time](cols.ArcgisRefreshTokenExpires),
|
||||||
ArcgisRole: psql.WhereNull[Q, string](cols.ArcgisRole),
|
ArcgisRole: psql.WhereNull[Q, string](cols.ArcgisRole),
|
||||||
DisplayName: psql.WhereNull[Q, string](cols.DisplayName),
|
DisplayName: psql.Where[Q, string](cols.DisplayName),
|
||||||
Email: psql.WhereNull[Q, string](cols.Email),
|
Email: psql.WhereNull[Q, string](cols.Email),
|
||||||
OrganizationID: psql.WhereNull[Q, int32](cols.OrganizationID),
|
OrganizationID: psql.WhereNull[Q, int32](cols.OrganizationID),
|
||||||
Username: psql.Where[Q, string](cols.Username),
|
Username: psql.Where[Q, string](cols.Username),
|
||||||
PasswordHashType: psql.WhereNull[Q, enums.Hashtype](cols.PasswordHashType),
|
PasswordHashType: psql.Where[Q, enums.Hashtype](cols.PasswordHashType),
|
||||||
PasswordHash: psql.WhereNull[Q, string](cols.PasswordHash),
|
PasswordHash: psql.Where[Q, string](cols.PasswordHash),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,12 @@ func formatQuery(s string) (string, error) {
|
||||||
|
|
||||||
var defaultFaker = faker.New()
|
var defaultFaker = faker.New()
|
||||||
|
|
||||||
func random_enums_ArcgisLicenseType(f *faker.Faker, limits ...string) enums.ArcgisLicenseType {
|
func random_enums_Arcgislicensetype(f *faker.Faker, limits ...string) enums.Arcgislicensetype {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
f = &defaultFaker
|
f = &defaultFaker
|
||||||
}
|
}
|
||||||
|
|
||||||
var e enums.ArcgisLicenseType
|
var e enums.Arcgislicensetype
|
||||||
all := e.All()
|
all := e.All()
|
||||||
return all[f.IntBetween(0, len(all)-1)]
|
return all[f.IntBetween(0, len(all)-1)]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,16 +72,16 @@ func UserByUsername(Username string) *UserByUsernameQuery {
|
||||||
type UserByUsernameRow = struct {
|
type UserByUsernameRow = struct {
|
||||||
ID int32 `db:"id"`
|
ID int32 `db:"id"`
|
||||||
ArcgisAccessToken null.Val[string] `db:"arcgis_access_token"`
|
ArcgisAccessToken null.Val[string] `db:"arcgis_access_token"`
|
||||||
ArcgisLicense null.Val[enums.ArcgisLicenseType] `db:"arcgis_license"`
|
ArcgisLicense null.Val[enums.Arcgislicensetype] `db:"arcgis_license"`
|
||||||
ArcgisRefreshToken null.Val[string] `db:"arcgis_refresh_token"`
|
ArcgisRefreshToken null.Val[string] `db:"arcgis_refresh_token"`
|
||||||
ArcgisRefreshTokenExpires null.Val[time.Time] `db:"arcgis_refresh_token_expires"`
|
ArcgisRefreshTokenExpires null.Val[time.Time] `db:"arcgis_refresh_token_expires"`
|
||||||
ArcgisRole null.Val[string] `db:"arcgis_role"`
|
ArcgisRole null.Val[string] `db:"arcgis_role"`
|
||||||
DisplayName null.Val[string] `db:"display_name"`
|
DisplayName string `db:"display_name"`
|
||||||
Email null.Val[string] `db:"email"`
|
Email null.Val[string] `db:"email"`
|
||||||
OrganizationID null.Val[int32] `db:"organization_id"`
|
OrganizationID null.Val[int32] `db:"organization_id"`
|
||||||
Username string `db:"username"`
|
Username string `db:"username"`
|
||||||
PasswordHashType null.Val[enums.Hashtype] `db:"password_hash_type"`
|
PasswordHashType enums.Hashtype `db:"password_hash_type"`
|
||||||
PasswordHash null.Val[string] `db:"password_hash"`
|
PasswordHash string `db:"password_hash"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type userByUsernameTransformer = bob.SliceTransformer[UserByUsernameRow, []UserByUsernameRow]
|
type userByUsernameTransformer = bob.SliceTransformer[UserByUsernameRow, []UserByUsernameRow]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue