Documentation
¶
Overview ¶
Package adminuser implements the admin-side account management subdomain of the identity module: user CRUD, auth methods, devices and login logs. Only the module facade may reach it.
Index ¶
- func IsValidImageSize(base64Str string, maxSizeKB int64) bool
- type Deps
- type ServerCaches
- type Service
- func (s *Service) BatchDeleteUser(ctx context.Context, req *dto.BatchDeleteUserRequest) error
- func (s *Service) CreateUser(ctx context.Context, req *dto.CreateUserRequest) error
- func (s *Service) CreateUserAuthMethod(ctx context.Context, req *dto.CreateUserAuthMethodRequest) error
- func (s *Service) CurrentUser(ctx context.Context) (*dto.User, error)
- func (s *Service) DeleteUser(ctx context.Context, req *dto.GetDetailRequest) error
- func (s *Service) DeleteUserAuthMethod(ctx context.Context, req *dto.DeleteUserAuthMethodRequest) error
- func (s *Service) DeleteUserDevice(ctx context.Context, req *dto.DeleteUserDeviceRequest) error
- func (s *Service) GetUserAuthMethod(ctx context.Context, req *dto.GetUserAuthMethodRequest) (*dto.GetUserAuthMethodResponse, error)
- func (s *Service) GetUserDetail(ctx context.Context, req *dto.GetDetailRequest) (*dto.User, error)
- func (s *Service) GetUserList(ctx context.Context, req *dto.GetUserListRequest) (*dto.GetUserListResponse, error)
- func (s *Service) GetUserLoginLogs(ctx context.Context, req *dto.GetUserLoginLogsRequest) (*dto.GetUserLoginLogsResponse, error)
- func (s *Service) KickOfflineByUserDevice(ctx context.Context, req *dto.KickOfflineRequest) error
- func (s *Service) SetUserEnabled(ctx context.Context, userID int64, enabled bool) error
- func (s *Service) UpdateUserAuthMethod(ctx context.Context, req *dto.UpdateUserAuthMethodRequest) error
- func (s *Service) UpdateUserBasicInfo(ctx context.Context, req *dto.UpdateUserBasicInfoRequest) error
- func (s *Service) UpdateUserDevice(ctx context.Context, req *dto.UserDevice) error
- func (s *Service) UpdateUserNotifySetting(ctx context.Context, req *dto.UpdateUserNotifySettingRequest) error
- type Store
- type SubscriptionCaches
- type UserAuths
- type Wallets
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidImageSize ¶ added in v1.20.2
IsValidImageSize reports whether base64Str, a Base64 image with or without a data URL prefix, decodes and is at most maxSizeKB kilobytes.
Types ¶
type Deps ¶
type Deps struct {
Users repository.UserRepo
UserAuths UserAuths
Devices repository.UserDeviceRepo
Cache repository.UserCacheRepo
// Logs is the read port onto the platform domain's login logs.
Logs repository.LogRepo
// Wallet is the port onto the billing domain: the admin views show
// wallet values from the authoritative table, not the legacy user
// columns (ADR-001 step 5), and the money edits run as billing's own
// transaction after the identity one.
Wallet Wallets
Store Store
Redis *redis.Client
// KickDevice force-disconnects a bound device.
KickDevice func(userID int64, identifier string)
// SubscriptionCaches and ServerCaches drop the subscription tokens and
// node user lists that keep serving an account after its access ended
// (the subscription and network facades).
SubscriptionCaches SubscriptionCaches
ServerCaches ServerCaches
}
Deps declares the subdomain's dependencies; the module facade forwards them from the composition root.
type ServerCaches ¶ added in v1.21.0
type ServerCaches interface {
// ClearServerCachesByNodeScope drops the caches of every server
// carrying a node the scope selects.
ClearServerCachesByNodeScope(ctx context.Context, nodeIDs []int64, tags []string) error
}
ServerCaches is the network module's invalidation of the node-facing server caches (the network facade).
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the admin account management entry point used by the identity facade.
func NewService ¶
NewService builds the subdomain over the dependencies the facade forwards.
func (*Service) BatchDeleteUser ¶
BatchDeleteUser soft-deletes the accounts and drops the caches that keep serving them. The demo instance's administrator cannot be deleted, and neither can the last enabled administrator.
func (*Service) CreateUser ¶
CreateUser creates an account on the administrator's behalf. Its phone number is stored in E.164 like every self-service one, so the account signs in and resets by phone; an identifier another account holds is refused.
func (*Service) CreateUserAuthMethod ¶
func (s *Service) CreateUserAuthMethod(ctx context.Context, req *dto.CreateUserAuthMethodRequest) error
CreateUserAuthMethod binds an identity to an account, or replaces the account's identity of that type. Emails and phone numbers are stored normalized, and one that cannot be is refused.
func (*Service) CurrentUser ¶
CurrentUser returns the signed-in administrator's account with its wallet.
func (*Service) DeleteUser ¶
DeleteUser soft-deletes the account and drops the caches that keep serving it. The demo instance's administrator cannot be deleted, and neither can the last enabled administrator.
func (*Service) DeleteUserAuthMethod ¶
func (s *Service) DeleteUserAuthMethod(ctx context.Context, req *dto.DeleteUserAuthMethodRequest) error
DeleteUserAuthMethod removes the account's identity of the given type. Device identities are removed with their device.
func (*Service) DeleteUserDevice ¶
DeleteUserDevice removes a device with its identity and sessions, and disconnects it.
func (*Service) GetUserAuthMethod ¶
func (s *Service) GetUserAuthMethod(ctx context.Context, req *dto.GetUserAuthMethodRequest) (*dto.GetUserAuthMethodResponse, error)
GetUserAuthMethod lists the account's identities as stored.
func (*Service) GetUserDetail ¶
GetUserDetail returns an account with its wallet, for the admin edit form.
func (*Service) GetUserList ¶
func (s *Service) GetUserList(ctx context.Context, req *dto.GetUserListRequest) (*dto.GetUserListResponse, error)
GetUserList pages the accounts, newest first, with their wallets. Phone numbers are shown in the international format.
func (*Service) GetUserLoginLogs ¶
func (s *Service) GetUserLoginLogs(ctx context.Context, req *dto.GetUserLoginLogsRequest) (*dto.GetUserLoginLogsResponse, error)
GetUserLoginLogs pages the sign-in audits of an account.
func (*Service) KickOfflineByUserDevice ¶
KickOfflineByUserDevice ends a device's sessions, disconnects it and shows it offline; the device stays bound.
func (*Service) SetUserEnabled ¶ added in v1.21.0
SetUserEnabled enables or disables an account for a caller outside the admin panel (the Telegram bot's ban and unban). Like the admin edit it writes only the flag, so a concurrent change to the account survives, and it invalidates the same subscription-token caches and node user lists, so a ban takes effect at the service plane at once instead of after the caches' TTL. The caller flips the state it just read, so the caches are invalidated after every write rather than only on a detected change.
func (*Service) UpdateUserAuthMethod ¶
func (s *Service) UpdateUserAuthMethod(ctx context.Context, req *dto.UpdateUserAuthMethodRequest) error
UpdateUserAuthMethod changes the identifier of an account's identity of the given type. Emails and phone numbers are stored normalized, and one that cannot be is refused.
func (*Service) UpdateUserBasicInfo ¶
func (s *Service) UpdateUserBasicInfo(ctx context.Context, req *dto.UpdateUserBasicInfoRequest) error
UpdateUserBasicInfo applies an administrator's edit of an account: its profile columns and, in a billing transaction of its own, its wallet.
func (*Service) UpdateUserDevice ¶
UpdateUserDevice enables or disables a device. Its sessions end either way, and a disabled device is disconnected.
func (*Service) UpdateUserNotifySetting ¶
func (s *Service) UpdateUserNotifySetting(ctx context.Context, req *dto.UpdateUserNotifySettingRequest) error
UpdateUserNotifySetting sets which notifications an account receives.
type Store ¶ added in v1.20.3
type Store interface {
repository.IdentityTransactor
}
Store is the persistence capability required by this package. It excludes unrelated repositories and application-wide transactions.
type SubscriptionCaches ¶ added in v1.21.0
type SubscriptionCaches interface {
// ClearUserSubscriptionCaches drops the cached subscriptions of the
// users and returns the node scope of their plans.
ClearUserSubscriptionCaches(ctx context.Context, userIDs []int64) (nodeIDs []int64, tags []string, err error)
}
SubscriptionCaches is the subscription module's cache invalidation for accounts whose access ended (the subscription facade).
type UserAuths ¶ added in v1.21.0
type UserAuths interface {
// FindUserAuthMethods returns every binding of the account.
FindUserAuthMethods(ctx context.Context, userID int64) ([]*user.AuthMethods, error)
// FindUserAuthMethodByOpenID returns the binding of method whose
// identifier is openID, the duplicate check of an account the
// administrator creates.
FindUserAuthMethodByOpenID(ctx context.Context, method, openID string) (*user.AuthMethods, error)
// FindUserAuthMethodByPlatform returns the account's binding of platform.
FindUserAuthMethodByPlatform(ctx context.Context, userID int64, platform string) (*user.AuthMethods, error)
UpdateUserAuthMethods(ctx context.Context, data *user.AuthMethods) error
DeleteUserAuthMethods(ctx context.Context, userID int64, platform string) error
}
UserAuths is the part of the identity bindings the admin flows read and change outside a transaction.
type Wallets ¶ added in v1.21.0
type Wallets interface {
// FindWallet reads a user's wallet; a user without a wallet row reads as
// nil. FindWallets reads several; users without a row are absent from
// the map.
FindWallet(ctx context.Context, userID int64) (*wallet.Wallet, error)
FindWallets(ctx context.Context, userIDs []int64) (map[int64]*wallet.Wallet, error)
// OpenWallet sets the opening amounts of an account the administrator
// created.
OpenWallet(ctx context.Context, opening wallet.Wallet) error
// AdjustWallet sets the wallet amounts the adjustment carries, auditing
// each change; amounts left nil or already equal are left alone.
AdjustWallet(ctx context.Context, adjustment wallet.Adjustment) error
}
Wallets is the billing port of the admin account flows; the billing facade provides it.
Source Files
¶
- avatar.go
- batchdeleteuser.go
- createuser.go
- createuserauthmethod.go
- currentuser.go
- deleteaccess.go
- deleteuser.go
- deleteuserauthmethod.go
- deleteuserdevice.go
- getuserauthmethod.go
- getuserdetail.go
- getuserlist.go
- getuserloginlogs.go
- kickofflinebyuserdevice.go
- lastadmin.go
- service.go
- setuserenabled.go
- updateuserauthmethod.go
- updateuserbasicinfo.go
- updateuserdevice.go
- updateusernotifysetting.go