diff --git a/backend/db/migrate/schema.go b/backend/db/migrate/schema.go index 82ddcfac..35f1d1b5 100644 --- a/backend/db/migrate/schema.go +++ b/backend/db/migrate/schema.go @@ -379,6 +379,7 @@ var ( {Name: "os_type", Type: field.TypeString, Nullable: true}, {Name: "os_release", Type: field.TypeString, Nullable: true}, {Name: "hostname", Type: field.TypeString, Nullable: true}, + {Name: "client_id", Type: field.TypeString, Nullable: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "user_id", Type: field.TypeUUID, Nullable: true}, } @@ -390,7 +391,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "user_login_histories_users_login_histories", - Columns: []*schema.Column{UserLoginHistoriesColumns[12]}, + Columns: []*schema.Column{UserLoginHistoriesColumns[13]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.SetNull, }, diff --git a/backend/db/mutation.go b/backend/db/mutation.go index 7b711e1c..bc77a7eb 100644 --- a/backend/db/mutation.go +++ b/backend/db/mutation.go @@ -14297,6 +14297,7 @@ type UserLoginHistoryMutation struct { os_type *consts.OSType os_release *consts.OSRelease hostname *string + client_id *string created_at *time.Time clearedFields map[string]struct{} owner *uuid.UUID @@ -14897,6 +14898,55 @@ func (m *UserLoginHistoryMutation) ResetHostname() { delete(m.clearedFields, userloginhistory.FieldHostname) } +// SetClientID sets the "client_id" field. +func (m *UserLoginHistoryMutation) SetClientID(s string) { + m.client_id = &s +} + +// ClientID returns the value of the "client_id" field in the mutation. +func (m *UserLoginHistoryMutation) ClientID() (r string, exists bool) { + v := m.client_id + if v == nil { + return + } + return *v, true +} + +// OldClientID returns the old "client_id" field's value of the UserLoginHistory entity. +// If the UserLoginHistory object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *UserLoginHistoryMutation) OldClientID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldClientID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldClientID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldClientID: %w", err) + } + return oldValue.ClientID, nil +} + +// ClearClientID clears the value of the "client_id" field. +func (m *UserLoginHistoryMutation) ClearClientID() { + m.client_id = nil + m.clearedFields[userloginhistory.FieldClientID] = struct{}{} +} + +// ClientIDCleared returns if the "client_id" field was cleared in this mutation. +func (m *UserLoginHistoryMutation) ClientIDCleared() bool { + _, ok := m.clearedFields[userloginhistory.FieldClientID] + return ok +} + +// ResetClientID resets all changes to the "client_id" field. +func (m *UserLoginHistoryMutation) ResetClientID() { + m.client_id = nil + delete(m.clearedFields, userloginhistory.FieldClientID) +} + // SetCreatedAt sets the "created_at" field. func (m *UserLoginHistoryMutation) SetCreatedAt(t time.Time) { m.created_at = &t @@ -15007,7 +15057,7 @@ func (m *UserLoginHistoryMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *UserLoginHistoryMutation) Fields() []string { - fields := make([]string, 0, 12) + fields := make([]string, 0, 13) if m.owner != nil { fields = append(fields, userloginhistory.FieldUserID) } @@ -15041,6 +15091,9 @@ func (m *UserLoginHistoryMutation) Fields() []string { if m.hostname != nil { fields = append(fields, userloginhistory.FieldHostname) } + if m.client_id != nil { + fields = append(fields, userloginhistory.FieldClientID) + } if m.created_at != nil { fields = append(fields, userloginhistory.FieldCreatedAt) } @@ -15074,6 +15127,8 @@ func (m *UserLoginHistoryMutation) Field(name string) (ent.Value, bool) { return m.OsRelease() case userloginhistory.FieldHostname: return m.Hostname() + case userloginhistory.FieldClientID: + return m.ClientID() case userloginhistory.FieldCreatedAt: return m.CreatedAt() } @@ -15107,6 +15162,8 @@ func (m *UserLoginHistoryMutation) OldField(ctx context.Context, name string) (e return m.OldOsRelease(ctx) case userloginhistory.FieldHostname: return m.OldHostname(ctx) + case userloginhistory.FieldClientID: + return m.OldClientID(ctx) case userloginhistory.FieldCreatedAt: return m.OldCreatedAt(ctx) } @@ -15195,6 +15252,13 @@ func (m *UserLoginHistoryMutation) SetField(name string, value ent.Value) error } m.SetHostname(v) return nil + case userloginhistory.FieldClientID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetClientID(v) + return nil case userloginhistory.FieldCreatedAt: v, ok := value.(time.Time) if !ok { @@ -15253,6 +15317,9 @@ func (m *UserLoginHistoryMutation) ClearedFields() []string { if m.FieldCleared(userloginhistory.FieldHostname) { fields = append(fields, userloginhistory.FieldHostname) } + if m.FieldCleared(userloginhistory.FieldClientID) { + fields = append(fields, userloginhistory.FieldClientID) + } return fields } @@ -15288,6 +15355,9 @@ func (m *UserLoginHistoryMutation) ClearField(name string) error { case userloginhistory.FieldHostname: m.ClearHostname() return nil + case userloginhistory.FieldClientID: + m.ClearClientID() + return nil } return fmt.Errorf("unknown UserLoginHistory nullable field %s", name) } @@ -15329,6 +15399,9 @@ func (m *UserLoginHistoryMutation) ResetField(name string) error { case userloginhistory.FieldHostname: m.ResetHostname() return nil + case userloginhistory.FieldClientID: + m.ResetClientID() + return nil case userloginhistory.FieldCreatedAt: m.ResetCreatedAt() return nil diff --git a/backend/db/runtime/runtime.go b/backend/db/runtime/runtime.go index 5110e1d3..3d2d22ac 100644 --- a/backend/db/runtime/runtime.go +++ b/backend/db/runtime/runtime.go @@ -319,7 +319,7 @@ func init() { userloginhistoryFields := schema.UserLoginHistory{}.Fields() _ = userloginhistoryFields // userloginhistoryDescCreatedAt is the schema descriptor for created_at field. - userloginhistoryDescCreatedAt := userloginhistoryFields[12].Descriptor() + userloginhistoryDescCreatedAt := userloginhistoryFields[13].Descriptor() // userloginhistory.DefaultCreatedAt holds the default value on creation for the created_at field. userloginhistory.DefaultCreatedAt = userloginhistoryDescCreatedAt.Default.(func() time.Time) } diff --git a/backend/db/userloginhistory.go b/backend/db/userloginhistory.go index 56a0b0cb..3b15e225 100644 --- a/backend/db/userloginhistory.go +++ b/backend/db/userloginhistory.go @@ -42,6 +42,8 @@ type UserLoginHistory struct { OsRelease consts.OSRelease `json:"os_release,omitempty"` // Hostname holds the value of the "hostname" field. Hostname string `json:"hostname,omitempty"` + // ClientID holds the value of the "client_id" field. + ClientID string `json:"client_id,omitempty"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at,omitempty"` // Edges holds the relations/edges for other nodes in the graph. @@ -75,7 +77,7 @@ func (*UserLoginHistory) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { - case userloginhistory.FieldIP, userloginhistory.FieldCountry, userloginhistory.FieldProvince, userloginhistory.FieldCity, userloginhistory.FieldIsp, userloginhistory.FieldAsn, userloginhistory.FieldClientVersion, userloginhistory.FieldOsType, userloginhistory.FieldOsRelease, userloginhistory.FieldHostname: + case userloginhistory.FieldIP, userloginhistory.FieldCountry, userloginhistory.FieldProvince, userloginhistory.FieldCity, userloginhistory.FieldIsp, userloginhistory.FieldAsn, userloginhistory.FieldClientVersion, userloginhistory.FieldOsType, userloginhistory.FieldOsRelease, userloginhistory.FieldHostname, userloginhistory.FieldClientID: values[i] = new(sql.NullString) case userloginhistory.FieldCreatedAt: values[i] = new(sql.NullTime) @@ -168,6 +170,12 @@ func (ulh *UserLoginHistory) assignValues(columns []string, values []any) error } else if value.Valid { ulh.Hostname = value.String } + case userloginhistory.FieldClientID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field client_id", values[i]) + } else if value.Valid { + ulh.ClientID = value.String + } case userloginhistory.FieldCreatedAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field created_at", values[i]) @@ -248,6 +256,9 @@ func (ulh *UserLoginHistory) String() string { builder.WriteString("hostname=") builder.WriteString(ulh.Hostname) builder.WriteString(", ") + builder.WriteString("client_id=") + builder.WriteString(ulh.ClientID) + builder.WriteString(", ") builder.WriteString("created_at=") builder.WriteString(ulh.CreatedAt.Format(time.ANSIC)) builder.WriteByte(')') diff --git a/backend/db/userloginhistory/userloginhistory.go b/backend/db/userloginhistory/userloginhistory.go index 8a34fcf3..7e0fa37a 100644 --- a/backend/db/userloginhistory/userloginhistory.go +++ b/backend/db/userloginhistory/userloginhistory.go @@ -36,6 +36,8 @@ const ( FieldOsRelease = "os_release" // FieldHostname holds the string denoting the hostname field in the database. FieldHostname = "hostname" + // FieldClientID holds the string denoting the client_id field in the database. + FieldClientID = "client_id" // FieldCreatedAt holds the string denoting the created_at field in the database. FieldCreatedAt = "created_at" // EdgeOwner holds the string denoting the owner edge name in mutations. @@ -65,6 +67,7 @@ var Columns = []string{ FieldOsType, FieldOsRelease, FieldHostname, + FieldClientID, FieldCreatedAt, } @@ -146,6 +149,11 @@ func ByHostname(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldHostname, opts...).ToFunc() } +// ByClientID orders the results by the client_id field. +func ByClientID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldClientID, opts...).ToFunc() +} + // ByCreatedAt orders the results by the created_at field. func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() diff --git a/backend/db/userloginhistory/where.go b/backend/db/userloginhistory/where.go index 8e283ead..34812b19 100644 --- a/backend/db/userloginhistory/where.go +++ b/backend/db/userloginhistory/where.go @@ -114,6 +114,11 @@ func Hostname(v string) predicate.UserLoginHistory { return predicate.UserLoginHistory(sql.FieldEQ(FieldHostname, v)) } +// ClientID applies equality check predicate on the "client_id" field. It's identical to ClientIDEQ. +func ClientID(v string) predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldEQ(FieldClientID, v)) +} + // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.UserLoginHistory { return predicate.UserLoginHistory(sql.FieldEQ(FieldCreatedAt, v)) @@ -897,6 +902,81 @@ func HostnameContainsFold(v string) predicate.UserLoginHistory { return predicate.UserLoginHistory(sql.FieldContainsFold(FieldHostname, v)) } +// ClientIDEQ applies the EQ predicate on the "client_id" field. +func ClientIDEQ(v string) predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldEQ(FieldClientID, v)) +} + +// ClientIDNEQ applies the NEQ predicate on the "client_id" field. +func ClientIDNEQ(v string) predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldNEQ(FieldClientID, v)) +} + +// ClientIDIn applies the In predicate on the "client_id" field. +func ClientIDIn(vs ...string) predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldIn(FieldClientID, vs...)) +} + +// ClientIDNotIn applies the NotIn predicate on the "client_id" field. +func ClientIDNotIn(vs ...string) predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldNotIn(FieldClientID, vs...)) +} + +// ClientIDGT applies the GT predicate on the "client_id" field. +func ClientIDGT(v string) predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldGT(FieldClientID, v)) +} + +// ClientIDGTE applies the GTE predicate on the "client_id" field. +func ClientIDGTE(v string) predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldGTE(FieldClientID, v)) +} + +// ClientIDLT applies the LT predicate on the "client_id" field. +func ClientIDLT(v string) predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldLT(FieldClientID, v)) +} + +// ClientIDLTE applies the LTE predicate on the "client_id" field. +func ClientIDLTE(v string) predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldLTE(FieldClientID, v)) +} + +// ClientIDContains applies the Contains predicate on the "client_id" field. +func ClientIDContains(v string) predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldContains(FieldClientID, v)) +} + +// ClientIDHasPrefix applies the HasPrefix predicate on the "client_id" field. +func ClientIDHasPrefix(v string) predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldHasPrefix(FieldClientID, v)) +} + +// ClientIDHasSuffix applies the HasSuffix predicate on the "client_id" field. +func ClientIDHasSuffix(v string) predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldHasSuffix(FieldClientID, v)) +} + +// ClientIDIsNil applies the IsNil predicate on the "client_id" field. +func ClientIDIsNil() predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldIsNull(FieldClientID)) +} + +// ClientIDNotNil applies the NotNil predicate on the "client_id" field. +func ClientIDNotNil() predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldNotNull(FieldClientID)) +} + +// ClientIDEqualFold applies the EqualFold predicate on the "client_id" field. +func ClientIDEqualFold(v string) predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldEqualFold(FieldClientID, v)) +} + +// ClientIDContainsFold applies the ContainsFold predicate on the "client_id" field. +func ClientIDContainsFold(v string) predicate.UserLoginHistory { + return predicate.UserLoginHistory(sql.FieldContainsFold(FieldClientID, v)) +} + // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.UserLoginHistory { return predicate.UserLoginHistory(sql.FieldEQ(FieldCreatedAt, v)) diff --git a/backend/db/userloginhistory_create.go b/backend/db/userloginhistory_create.go index 55e1a85f..269c01ff 100644 --- a/backend/db/userloginhistory_create.go +++ b/backend/db/userloginhistory_create.go @@ -148,6 +148,20 @@ func (ulhc *UserLoginHistoryCreate) SetNillableHostname(s *string) *UserLoginHis return ulhc } +// SetClientID sets the "client_id" field. +func (ulhc *UserLoginHistoryCreate) SetClientID(s string) *UserLoginHistoryCreate { + ulhc.mutation.SetClientID(s) + return ulhc +} + +// SetNillableClientID sets the "client_id" field if the given value is not nil. +func (ulhc *UserLoginHistoryCreate) SetNillableClientID(s *string) *UserLoginHistoryCreate { + if s != nil { + ulhc.SetClientID(*s) + } + return ulhc +} + // SetCreatedAt sets the "created_at" field. func (ulhc *UserLoginHistoryCreate) SetCreatedAt(t time.Time) *UserLoginHistoryCreate { ulhc.mutation.SetCreatedAt(t) @@ -321,6 +335,10 @@ func (ulhc *UserLoginHistoryCreate) createSpec() (*UserLoginHistory, *sqlgraph.C _spec.SetField(userloginhistory.FieldHostname, field.TypeString, value) _node.Hostname = value } + if value, ok := ulhc.mutation.ClientID(); ok { + _spec.SetField(userloginhistory.FieldClientID, field.TypeString, value) + _node.ClientID = value + } if value, ok := ulhc.mutation.CreatedAt(); ok { _spec.SetField(userloginhistory.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value @@ -568,6 +586,24 @@ func (u *UserLoginHistoryUpsert) ClearHostname() *UserLoginHistoryUpsert { return u } +// SetClientID sets the "client_id" field. +func (u *UserLoginHistoryUpsert) SetClientID(v string) *UserLoginHistoryUpsert { + u.Set(userloginhistory.FieldClientID, v) + return u +} + +// UpdateClientID sets the "client_id" field to the value that was provided on create. +func (u *UserLoginHistoryUpsert) UpdateClientID() *UserLoginHistoryUpsert { + u.SetExcluded(userloginhistory.FieldClientID) + return u +} + +// ClearClientID clears the value of the "client_id" field. +func (u *UserLoginHistoryUpsert) ClearClientID() *UserLoginHistoryUpsert { + u.SetNull(userloginhistory.FieldClientID) + return u +} + // SetCreatedAt sets the "created_at" field. func (u *UserLoginHistoryUpsert) SetCreatedAt(v time.Time) *UserLoginHistoryUpsert { u.Set(userloginhistory.FieldCreatedAt, v) @@ -831,6 +867,27 @@ func (u *UserLoginHistoryUpsertOne) ClearHostname() *UserLoginHistoryUpsertOne { }) } +// SetClientID sets the "client_id" field. +func (u *UserLoginHistoryUpsertOne) SetClientID(v string) *UserLoginHistoryUpsertOne { + return u.Update(func(s *UserLoginHistoryUpsert) { + s.SetClientID(v) + }) +} + +// UpdateClientID sets the "client_id" field to the value that was provided on create. +func (u *UserLoginHistoryUpsertOne) UpdateClientID() *UserLoginHistoryUpsertOne { + return u.Update(func(s *UserLoginHistoryUpsert) { + s.UpdateClientID() + }) +} + +// ClearClientID clears the value of the "client_id" field. +func (u *UserLoginHistoryUpsertOne) ClearClientID() *UserLoginHistoryUpsertOne { + return u.Update(func(s *UserLoginHistoryUpsert) { + s.ClearClientID() + }) +} + // SetCreatedAt sets the "created_at" field. func (u *UserLoginHistoryUpsertOne) SetCreatedAt(v time.Time) *UserLoginHistoryUpsertOne { return u.Update(func(s *UserLoginHistoryUpsert) { @@ -1263,6 +1320,27 @@ func (u *UserLoginHistoryUpsertBulk) ClearHostname() *UserLoginHistoryUpsertBulk }) } +// SetClientID sets the "client_id" field. +func (u *UserLoginHistoryUpsertBulk) SetClientID(v string) *UserLoginHistoryUpsertBulk { + return u.Update(func(s *UserLoginHistoryUpsert) { + s.SetClientID(v) + }) +} + +// UpdateClientID sets the "client_id" field to the value that was provided on create. +func (u *UserLoginHistoryUpsertBulk) UpdateClientID() *UserLoginHistoryUpsertBulk { + return u.Update(func(s *UserLoginHistoryUpsert) { + s.UpdateClientID() + }) +} + +// ClearClientID clears the value of the "client_id" field. +func (u *UserLoginHistoryUpsertBulk) ClearClientID() *UserLoginHistoryUpsertBulk { + return u.Update(func(s *UserLoginHistoryUpsert) { + s.ClearClientID() + }) +} + // SetCreatedAt sets the "created_at" field. func (u *UserLoginHistoryUpsertBulk) SetCreatedAt(v time.Time) *UserLoginHistoryUpsertBulk { return u.Update(func(s *UserLoginHistoryUpsert) { diff --git a/backend/db/userloginhistory_update.go b/backend/db/userloginhistory_update.go index 085a2aaf..786d60de 100644 --- a/backend/db/userloginhistory_update.go +++ b/backend/db/userloginhistory_update.go @@ -228,6 +228,26 @@ func (ulhu *UserLoginHistoryUpdate) ClearHostname() *UserLoginHistoryUpdate { return ulhu } +// SetClientID sets the "client_id" field. +func (ulhu *UserLoginHistoryUpdate) SetClientID(s string) *UserLoginHistoryUpdate { + ulhu.mutation.SetClientID(s) + return ulhu +} + +// SetNillableClientID sets the "client_id" field if the given value is not nil. +func (ulhu *UserLoginHistoryUpdate) SetNillableClientID(s *string) *UserLoginHistoryUpdate { + if s != nil { + ulhu.SetClientID(*s) + } + return ulhu +} + +// ClearClientID clears the value of the "client_id" field. +func (ulhu *UserLoginHistoryUpdate) ClearClientID() *UserLoginHistoryUpdate { + ulhu.mutation.ClearClientID() + return ulhu +} + // SetCreatedAt sets the "created_at" field. func (ulhu *UserLoginHistoryUpdate) SetCreatedAt(t time.Time) *UserLoginHistoryUpdate { ulhu.mutation.SetCreatedAt(t) @@ -362,6 +382,12 @@ func (ulhu *UserLoginHistoryUpdate) sqlSave(ctx context.Context) (n int, err err if ulhu.mutation.HostnameCleared() { _spec.ClearField(userloginhistory.FieldHostname, field.TypeString) } + if value, ok := ulhu.mutation.ClientID(); ok { + _spec.SetField(userloginhistory.FieldClientID, field.TypeString, value) + } + if ulhu.mutation.ClientIDCleared() { + _spec.ClearField(userloginhistory.FieldClientID, field.TypeString) + } if value, ok := ulhu.mutation.CreatedAt(); ok { _spec.SetField(userloginhistory.FieldCreatedAt, field.TypeTime, value) } @@ -612,6 +638,26 @@ func (ulhuo *UserLoginHistoryUpdateOne) ClearHostname() *UserLoginHistoryUpdateO return ulhuo } +// SetClientID sets the "client_id" field. +func (ulhuo *UserLoginHistoryUpdateOne) SetClientID(s string) *UserLoginHistoryUpdateOne { + ulhuo.mutation.SetClientID(s) + return ulhuo +} + +// SetNillableClientID sets the "client_id" field if the given value is not nil. +func (ulhuo *UserLoginHistoryUpdateOne) SetNillableClientID(s *string) *UserLoginHistoryUpdateOne { + if s != nil { + ulhuo.SetClientID(*s) + } + return ulhuo +} + +// ClearClientID clears the value of the "client_id" field. +func (ulhuo *UserLoginHistoryUpdateOne) ClearClientID() *UserLoginHistoryUpdateOne { + ulhuo.mutation.ClearClientID() + return ulhuo +} + // SetCreatedAt sets the "created_at" field. func (ulhuo *UserLoginHistoryUpdateOne) SetCreatedAt(t time.Time) *UserLoginHistoryUpdateOne { ulhuo.mutation.SetCreatedAt(t) @@ -776,6 +822,12 @@ func (ulhuo *UserLoginHistoryUpdateOne) sqlSave(ctx context.Context) (_node *Use if ulhuo.mutation.HostnameCleared() { _spec.ClearField(userloginhistory.FieldHostname, field.TypeString) } + if value, ok := ulhuo.mutation.ClientID(); ok { + _spec.SetField(userloginhistory.FieldClientID, field.TypeString, value) + } + if ulhuo.mutation.ClientIDCleared() { + _spec.ClearField(userloginhistory.FieldClientID, field.TypeString) + } if value, ok := ulhuo.mutation.CreatedAt(); ok { _spec.SetField(userloginhistory.FieldCreatedAt, field.TypeTime, value) } diff --git a/backend/domain/user.go b/backend/domain/user.go index 0972a13a..77093075 100644 --- a/backend/domain/user.go +++ b/backend/domain/user.go @@ -2,7 +2,6 @@ package domain import ( "context" - "fmt" "github.com/GoYoko/web" @@ -142,6 +141,8 @@ type UserLoginHistory struct { IPInfo *IPInfo `json:"ip_info"` // IP信息 ClientVersion string `json:"client_version"` // 客户端版本 Device string `json:"device"` // 设备信息 + Hostname string `json:"hostname"` // 主机名 + ClientID string `json:"client_id"` // 插件ID vscode CreatedAt int64 `json:"created_at"` // 登录时间 } @@ -161,9 +162,8 @@ func (l *UserLoginHistory) From(e *db.UserLoginHistory) *UserLoginHistory { } l.ClientVersion = e.ClientVersion l.Device = e.OsType.Name() - if e.Hostname != "" { - l.Device += fmt.Sprintf(" (%s)", e.Hostname) - } + l.Hostname = e.Hostname + l.ClientID = e.ClientID l.CreatedAt = e.CreatedAt.Unix() return l @@ -218,6 +218,7 @@ type User struct { Status consts.UserStatus `json:"status"` // 用户状态 active: 正常 locked: 锁定 inactive: 禁用 AvatarURL string `json:"avatar_url"` // 头像URL CreatedAt int64 `json:"created_at"` // 创建时间 + IsDeleted bool `json:"is_deleted"` // 是否删除 LastActiveAt int64 `json:"last_active_at"` // 最后活跃时间 } @@ -231,6 +232,7 @@ func (u *User) From(e *db.User) *User { u.Email = e.Email u.Status = e.Status u.AvatarURL = e.AvatarURL + u.IsDeleted = !e.DeletedAt.IsZero() u.CreatedAt = e.CreatedAt.Unix() return u @@ -259,6 +261,7 @@ func (a *AdminUser) From(e *db.Admin) *AdminUser { type VSCodeSession struct { ID string `json:"id"` // 会话ID + ClientID string `json:"client_id"` // 客户端ID State string `json:"state"` // 状态 RedirectURI string `json:"redirect_uri"` // 重定向URI Version string `json:"version"` // 版本 diff --git a/backend/ent/schema/userloginhistory.go b/backend/ent/schema/userloginhistory.go index c4bcf256..8e00b473 100644 --- a/backend/ent/schema/userloginhistory.go +++ b/backend/ent/schema/userloginhistory.go @@ -41,6 +41,7 @@ func (UserLoginHistory) Fields() []ent.Field { field.String("os_type").GoType(consts.OSType("")).Optional(), field.String("os_release").GoType(consts.OSRelease("")).Optional(), field.String("hostname").Optional(), + field.String("client_id").Optional(), field.Time("created_at").Default(time.Now), } } diff --git a/backend/internal/user/repo/user.go b/backend/internal/user/repo/user.go index eadc4f94..08a57d6c 100644 --- a/backend/internal/user/repo/user.go +++ b/backend/internal/user/repo/user.go @@ -122,6 +122,7 @@ func (r *UserRepo) CreateUser(ctx context.Context, user *db.User) (*db.User, err } func (r *UserRepo) UserLoginHistory(ctx context.Context, page *web.Pagination) ([]*db.UserLoginHistory, *db.PageInfo, error) { + ctx = entx.SkipSoftDelete(ctx) q := r.db.UserLoginHistory.Query().WithOwner().Order(userloginhistory.ByCreatedAt(sql.OrderDesc())) return q.Page(ctx, page.Page, page.Size) } @@ -428,6 +429,7 @@ func (r *UserRepo) SaveUserLoginHistory(ctx context.Context, userID string, ip s SetClientVersion(session.Version). SetOsType(session.OSType). SetOsRelease(session.OSRelease). + SetClientID(session.ClientID). SetHostname(session.Hostname). Save(ctx) return err diff --git a/backend/internal/user/usecase/user.go b/backend/internal/user/usecase/user.go index e9a6de2c..52c9db16 100644 --- a/backend/internal/user/usecase/user.go +++ b/backend/internal/user/usecase/user.go @@ -255,6 +255,7 @@ func (u *UserUsecase) VSCodeAuthInit(ctx context.Context, req *domain.VSCodeAuth i := uuid.NewString() session := &domain.VSCodeSession{ ID: i, + ClientID: req.ClientID, State: req.State, RedirectURI: req.RedirectURI, Version: req.Version, diff --git a/backend/migration/000008_alter_user_login_histories_table.up.sql b/backend/migration/000008_alter_user_login_histories_table.up.sql index dbf42376..3f680b0d 100644 --- a/backend/migration/000008_alter_user_login_histories_table.up.sql +++ b/backend/migration/000008_alter_user_login_histories_table.up.sql @@ -3,3 +3,4 @@ ALTER TABLE user_login_histories DROP COLUMN IF EXISTS device; ALTER TABLE user_login_histories ADD COLUMN IF NOT EXISTS hostname VARCHAR(255); ALTER TABLE user_login_histories ADD COLUMN IF NOT EXISTS os_type VARCHAR(255); ALTER TABLE user_login_histories ADD COLUMN IF NOT EXISTS os_release VARCHAR(255); +ALTER TABLE user_login_histories ADD COLUMN IF NOT EXISTS client_id VARCHAR(255); \ No newline at end of file