2025-07-25 15:09:56: merge [main:fb882e5c5c84ea63967c2aa6e330dab7a9521182];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s

This commit is contained in:
txix committed 2025-07-25 15:09:56 +03:00
1 parent 7c9e12685d
commit 121f63f57a
24 files changed
+150 -510

No files matched your search

+3 -21
View File
@@ -19,48 +19,35 @@ type AuditRepo interface {
SaveAuditAsync(ctx context.Context, userId int64, message string, event string)
}
type TokenRepo interface {
LastAccessNotBlockedUsers(ctx context.Context) (map[int64]time.Time, error)
}
type UserRepo interface {
LastAccessNotBlockedUsers(ctx context.Context) (map[int64]time.Time, error)
Block(ctx context.Context, userId int) (*entity.User, error)
}
type LdapService interface {
SyncGroups(ctx context.Context, user entity.User) error
}
type UserRoleRepo interface {
UpsertUserRoleLinks(ctx context.Context, id int, roleIds []int) error
}
type Service struct {
tokenRepo TokenRepo
userRepo UserRepo
auditRepo AuditRepo
userRoleRepo UserRoleRepo
ldapService LdapService
threshold time.Duration
syncPeriod time.Duration
logger log.Logger
}
func NewInactiveBlocker(
tokensRepo TokenRepo,
userRepo UserRepo,
auditRepo AuditRepo,
userRoleRepo UserRoleRepo,
ldapService LdapService,
config conf.BlockInactiveWorker,
logger log.Logger,
) Service {
return Service{
tokenRepo: tokensRepo,
userRepo: userRepo,
auditRepo: auditRepo,
userRoleRepo: userRoleRepo,
ldapService: ldapService,
threshold: time.Duration(config.DaysThreshold) * 24 * time.Hour,
syncPeriod: time.Minute * time.Duration(config.RunIntervalInMinutes),
logger: logger,
@@ -79,7 +66,7 @@ func (w Service) Handle(ctx context.Context, _ bgjob.Job) bgjob.Result {
}
func (w Service) do(ctx context.Context) error {
lastAccess, err := w.tokenRepo.LastAccessNotBlockedUsers(ctx)
lastAccess, err := w.userRepo.LastAccessNotBlockedUsers(ctx)
if err != nil {
return errors.WithMessage(err, "get last access times")
}
@@ -92,7 +79,7 @@ func (w Service) do(ctx context.Context) error {
}
w.logger.Info(ctx, "block inactive user", log.Int64("userId", userId), log.Any("lastAccessTime", lastAccess))
user, err := w.userRepo.Block(ctx, int(userId))
_, err := w.userRepo.Block(ctx, int(userId))
if err != nil {
return errors.WithMessagef(err, "block user %d", userId)
}
@@ -102,11 +89,6 @@ func (w Service) do(ctx context.Context) error {
return errors.WithMessage(err, "empty user roles links")
}
err = w.ldapService.SyncGroups(ctx, *user)
if err != nil {
w.logger.Error(ctx, errors.WithMessage(err, "remove ldap groups"))
}
w.auditRepo.SaveAuditAsync(ctx, userId, "Блокировка неактивной УЗ", entity.EventUserChanged)
}