mirror of
https://github.com/h44z/wg-portal
synced 2025-02-26 05:49:14 +00:00
code cleanup
This commit is contained in:
parent
26d3257516
commit
63d85d8123
@ -129,8 +129,8 @@ func (a *App) createDefaultUser(ctx context.Context) error {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
admin, err := a.CreateUser(ctx, &domain.User{
|
admin, err := a.CreateUser(ctx, &domain.User{
|
||||||
BaseModel: domain.BaseModel{
|
BaseModel: domain.BaseModel{
|
||||||
CreatedBy: "system",
|
CreatedBy: domain.CtxSystemAdminId,
|
||||||
UpdatedBy: "system",
|
UpdatedBy: domain.CtxSystemAdminId,
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
},
|
},
|
||||||
|
@ -98,8 +98,8 @@ func migrateV1Users(oldDb, newDb *gorm.DB) error {
|
|||||||
}
|
}
|
||||||
newUser := domain.User{
|
newUser := domain.User{
|
||||||
BaseModel: domain.BaseModel{
|
BaseModel: domain.BaseModel{
|
||||||
CreatedBy: "v1migrator",
|
CreatedBy: domain.CtxSystemV1Migrator,
|
||||||
UpdatedBy: "v1migrator",
|
UpdatedBy: domain.CtxSystemV1Migrator,
|
||||||
CreatedAt: oldUser.CreatedAt,
|
CreatedAt: oldUser.CreatedAt,
|
||||||
UpdatedAt: oldUser.UpdatedAt,
|
UpdatedAt: oldUser.UpdatedAt,
|
||||||
},
|
},
|
||||||
@ -173,8 +173,8 @@ func migrateV1Interfaces(oldDb, newDb *gorm.DB) error {
|
|||||||
}
|
}
|
||||||
newInterface := domain.Interface{
|
newInterface := domain.Interface{
|
||||||
BaseModel: domain.BaseModel{
|
BaseModel: domain.BaseModel{
|
||||||
CreatedBy: "v1migrator",
|
CreatedBy: domain.CtxSystemV1Migrator,
|
||||||
UpdatedBy: "v1migrator",
|
UpdatedBy: domain.CtxSystemV1Migrator,
|
||||||
CreatedAt: oldDevice.CreatedAt,
|
CreatedAt: oldDevice.CreatedAt,
|
||||||
UpdatedAt: oldDevice.UpdatedAt,
|
UpdatedAt: oldDevice.UpdatedAt,
|
||||||
},
|
},
|
||||||
@ -299,8 +299,8 @@ func migrateV1Peers(oldDb, newDb *gorm.DB) error {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
user = domain.User{
|
user = domain.User{
|
||||||
BaseModel: domain.BaseModel{
|
BaseModel: domain.BaseModel{
|
||||||
CreatedBy: "v1migrator",
|
CreatedBy: domain.CtxSystemV1Migrator,
|
||||||
UpdatedBy: "v1migrator",
|
UpdatedBy: domain.CtxSystemV1Migrator,
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
},
|
},
|
||||||
@ -322,8 +322,8 @@ func migrateV1Peers(oldDb, newDb *gorm.DB) error {
|
|||||||
}
|
}
|
||||||
newPeer := domain.Peer{
|
newPeer := domain.Peer{
|
||||||
BaseModel: domain.BaseModel{
|
BaseModel: domain.BaseModel{
|
||||||
CreatedBy: "v1migrator",
|
CreatedBy: domain.CtxSystemV1Migrator,
|
||||||
UpdatedBy: "v1migrator",
|
UpdatedBy: domain.CtxSystemV1Migrator,
|
||||||
CreatedAt: oldPeer.CreatedAt,
|
CreatedAt: oldPeer.CreatedAt,
|
||||||
UpdatedAt: oldPeer.UpdatedAt,
|
UpdatedAt: oldPeer.UpdatedAt,
|
||||||
},
|
},
|
||||||
|
@ -2,15 +2,21 @@ package users
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/go-ldap/ldap/v3"
|
"github.com/go-ldap/ldap/v3"
|
||||||
"github.com/h44z/wg-portal/internal"
|
"github.com/h44z/wg-portal/internal"
|
||||||
"github.com/h44z/wg-portal/internal/config"
|
"github.com/h44z/wg-portal/internal/config"
|
||||||
"github.com/h44z/wg-portal/internal/domain"
|
"github.com/h44z/wg-portal/internal/domain"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func convertRawLdapUser(providerName string, rawUser map[string]any, fields *config.LdapFields, adminGroupDN *ldap.DN) (*domain.User, error) {
|
func convertRawLdapUser(
|
||||||
|
providerName string,
|
||||||
|
rawUser map[string]any,
|
||||||
|
fields *config.LdapFields,
|
||||||
|
adminGroupDN *ldap.DN,
|
||||||
|
) (*domain.User, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
isAdmin, err := internal.LdapIsMemberOf(rawUser[fields.GroupMembership].([][]byte), adminGroupDN)
|
isAdmin, err := internal.LdapIsMemberOf(rawUser[fields.GroupMembership].([][]byte), adminGroupDN)
|
||||||
@ -20,8 +26,8 @@ func convertRawLdapUser(providerName string, rawUser map[string]any, fields *con
|
|||||||
|
|
||||||
return &domain.User{
|
return &domain.User{
|
||||||
BaseModel: domain.BaseModel{
|
BaseModel: domain.BaseModel{
|
||||||
CreatedBy: "ldap_sync",
|
CreatedBy: domain.CtxSystemLdapSyncer,
|
||||||
UpdatedBy: "ldap_sync",
|
UpdatedBy: domain.CtxSystemLdapSyncer,
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
},
|
},
|
||||||
|
@ -513,7 +513,7 @@ func (m Manager) updateLdapUsers(
|
|||||||
|
|
||||||
err := m.users.SaveUser(tctx, user.Identifier, func(u *domain.User) (*domain.User, error) {
|
err := m.users.SaveUser(tctx, user.Identifier, func(u *domain.User) (*domain.User, error) {
|
||||||
u.UpdatedAt = time.Now()
|
u.UpdatedAt = time.Now()
|
||||||
u.UpdatedBy = "ldap_sync"
|
u.UpdatedBy = domain.CtxSystemLdapSyncer
|
||||||
u.Email = user.Email
|
u.Email = user.Email
|
||||||
u.Firstname = user.Firstname
|
u.Firstname = user.Firstname
|
||||||
u.Lastname = user.Lastname
|
u.Lastname = user.Lastname
|
||||||
|
@ -705,8 +705,8 @@ func (m Manager) importInterface(ctx context.Context, in *domain.PhysicalInterfa
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
iface := domain.ConvertPhysicalInterface(in)
|
iface := domain.ConvertPhysicalInterface(in)
|
||||||
iface.BaseModel = domain.BaseModel{
|
iface.BaseModel = domain.BaseModel{
|
||||||
CreatedBy: "importer",
|
CreatedBy: domain.CtxSystemWgImporter,
|
||||||
UpdatedBy: "importer",
|
UpdatedBy: domain.CtxSystemWgImporter,
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
@ -742,8 +742,8 @@ func (m Manager) importPeer(ctx context.Context, in *domain.Interface, p *domain
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
peer := domain.ConvertPhysicalPeer(p)
|
peer := domain.ConvertPhysicalPeer(p)
|
||||||
peer.BaseModel = domain.BaseModel{
|
peer.BaseModel = domain.BaseModel{
|
||||||
CreatedBy: "importer",
|
CreatedBy: domain.CtxSystemWgImporter,
|
||||||
UpdatedBy: "importer",
|
UpdatedBy: domain.CtxSystemWgImporter,
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,11 @@ import (
|
|||||||
const CtxUserInfo = "userInfo"
|
const CtxUserInfo = "userInfo"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CtxSystemAdminId = "_WG_SYS_ADMIN_"
|
CtxSystemAdminId = "_WG_SYS_ADMIN_"
|
||||||
CtxUnknownUserId = "_WG_SYS_UNKNOWN_"
|
CtxUnknownUserId = "_WG_SYS_UNKNOWN_"
|
||||||
|
CtxSystemLdapSyncer = "_WG_SYS_LDAP_SYNCER_"
|
||||||
|
CtxSystemWgImporter = "_WG_SYS_WG_IMPORTER_"
|
||||||
|
CtxSystemV1Migrator = "_WG_SYS_V1_MIGRATOR_"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ContextUserInfo struct {
|
type ContextUserInfo struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user