mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-19 05:35:16 +01:00
Soft delete users (#476)
* Update Makefile * Optionally load test DB from env variable * Add option to soft-delete a user This allows users to be marked as deleted. An additional middleware checks if a user is deleted or deactivated and rejects requests for those as StatusUnauthorized. note: the middelware adds an additional DB query to load the user.
This commit is contained in:
@@ -78,7 +78,7 @@ func (svc *LndhubService) CreateUser(ctx context.Context, login string, password
|
||||
return user, err
|
||||
}
|
||||
|
||||
func (svc *LndhubService) UpdateUser(ctx context.Context, userId int64, login *string, password *string, deactivated *bool) (user *models.User, err error) {
|
||||
func (svc *LndhubService) UpdateUser(ctx context.Context, userId int64, login *string, password *string, deactivated *bool, deleted *bool) (user *models.User, err error) {
|
||||
user, err = svc.FindUser(ctx, userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -99,6 +99,14 @@ func (svc *LndhubService) UpdateUser(ctx context.Context, userId int64, login *s
|
||||
if deactivated != nil {
|
||||
user.Deactivated = *deactivated
|
||||
}
|
||||
// if a user gets deleted we mark it as deactivated and deleted
|
||||
// un-deleting it is not supported currently
|
||||
if deleted != nil {
|
||||
if *deleted == true {
|
||||
user.Deactivated = true
|
||||
user.Deleted = true
|
||||
}
|
||||
}
|
||||
_, err = svc.DB.NewUpdate().Model(user).WherePK().Exec(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user