feat: add roles, activation, superuser fields on user (#38)

This commit is contained in:
Hayden 2022-10-09 09:44:13 -08:00 committed by GitHub
parent a6d2fd45df
commit 0c90b05dca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 705 additions and 12 deletions

View file

@ -3,6 +3,7 @@
package user
import (
"fmt"
"time"
"github.com/google/uuid"
@ -25,6 +26,12 @@ const (
FieldPassword = "password"
// FieldIsSuperuser holds the string denoting the is_superuser field in the database.
FieldIsSuperuser = "is_superuser"
// FieldRole holds the string denoting the role field in the database.
FieldRole = "role"
// FieldSuperuser holds the string denoting the superuser field in the database.
FieldSuperuser = "superuser"
// FieldActivatedOn holds the string denoting the activated_on field in the database.
FieldActivatedOn = "activated_on"
// EdgeGroup holds the string denoting the group edge name in mutations.
EdgeGroup = "group"
// EdgeAuthTokens holds the string denoting the auth_tokens edge name in mutations.
@ -56,6 +63,9 @@ var Columns = []string{
FieldEmail,
FieldPassword,
FieldIsSuperuser,
FieldRole,
FieldSuperuser,
FieldActivatedOn,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the "users"
@ -94,6 +104,34 @@ var (
PasswordValidator func(string) error
// DefaultIsSuperuser holds the default value on creation for the "is_superuser" field.
DefaultIsSuperuser bool
// DefaultSuperuser holds the default value on creation for the "superuser" field.
DefaultSuperuser bool
// DefaultID holds the default value on creation for the "id" field.
DefaultID func() uuid.UUID
)
// Role defines the type for the "role" enum field.
type Role string
// RoleUser is the default value of the Role enum.
const DefaultRole = RoleUser
// Role values.
const (
RoleUser Role = "user"
RoleOwner Role = "owner"
)
func (r Role) String() string {
return string(r)
}
// RoleValidator is a validator for the "role" field enum values. It is called by the builders before save.
func RoleValidator(r Role) error {
switch r {
case RoleUser, RoleOwner:
return nil
default:
return fmt.Errorf("user: invalid enum value for role field: %q", r)
}
}

View file

@ -124,6 +124,20 @@ func IsSuperuser(v bool) predicate.User {
})
}
// Superuser applies equality check predicate on the "superuser" field. It's identical to SuperuserEQ.
func Superuser(v bool) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldSuperuser), v))
})
}
// ActivatedOn applies equality check predicate on the "activated_on" field. It's identical to ActivatedOnEQ.
func ActivatedOn(v time.Time) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldActivatedOn), v))
})
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.User {
return predicate.User(func(s *sql.Selector) {
@ -563,6 +577,134 @@ func IsSuperuserNEQ(v bool) predicate.User {
})
}
// RoleEQ applies the EQ predicate on the "role" field.
func RoleEQ(v Role) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldRole), v))
})
}
// RoleNEQ applies the NEQ predicate on the "role" field.
func RoleNEQ(v Role) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldRole), v))
})
}
// RoleIn applies the In predicate on the "role" field.
func RoleIn(vs ...Role) predicate.User {
v := make([]any, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.User(func(s *sql.Selector) {
s.Where(sql.In(s.C(FieldRole), v...))
})
}
// RoleNotIn applies the NotIn predicate on the "role" field.
func RoleNotIn(vs ...Role) predicate.User {
v := make([]any, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.User(func(s *sql.Selector) {
s.Where(sql.NotIn(s.C(FieldRole), v...))
})
}
// SuperuserEQ applies the EQ predicate on the "superuser" field.
func SuperuserEQ(v bool) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldSuperuser), v))
})
}
// SuperuserNEQ applies the NEQ predicate on the "superuser" field.
func SuperuserNEQ(v bool) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldSuperuser), v))
})
}
// ActivatedOnEQ applies the EQ predicate on the "activated_on" field.
func ActivatedOnEQ(v time.Time) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldActivatedOn), v))
})
}
// ActivatedOnNEQ applies the NEQ predicate on the "activated_on" field.
func ActivatedOnNEQ(v time.Time) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldActivatedOn), v))
})
}
// ActivatedOnIn applies the In predicate on the "activated_on" field.
func ActivatedOnIn(vs ...time.Time) predicate.User {
v := make([]any, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.User(func(s *sql.Selector) {
s.Where(sql.In(s.C(FieldActivatedOn), v...))
})
}
// ActivatedOnNotIn applies the NotIn predicate on the "activated_on" field.
func ActivatedOnNotIn(vs ...time.Time) predicate.User {
v := make([]any, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.User(func(s *sql.Selector) {
s.Where(sql.NotIn(s.C(FieldActivatedOn), v...))
})
}
// ActivatedOnGT applies the GT predicate on the "activated_on" field.
func ActivatedOnGT(v time.Time) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldActivatedOn), v))
})
}
// ActivatedOnGTE applies the GTE predicate on the "activated_on" field.
func ActivatedOnGTE(v time.Time) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldActivatedOn), v))
})
}
// ActivatedOnLT applies the LT predicate on the "activated_on" field.
func ActivatedOnLT(v time.Time) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldActivatedOn), v))
})
}
// ActivatedOnLTE applies the LTE predicate on the "activated_on" field.
func ActivatedOnLTE(v time.Time) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldActivatedOn), v))
})
}
// ActivatedOnIsNil applies the IsNil predicate on the "activated_on" field.
func ActivatedOnIsNil() predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.IsNull(s.C(FieldActivatedOn)))
})
}
// ActivatedOnNotNil applies the NotNil predicate on the "activated_on" field.
func ActivatedOnNotNil() predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.NotNull(s.C(FieldActivatedOn)))
})
}
// HasGroup applies the HasEdge predicate on the "group" edge.
func HasGroup() predicate.User {
return predicate.User(func(s *sql.Selector) {