fix: sync non-PTS moderation updates
This commit is contained in:
parent
cc76cd3679
commit
70e57b4d07
15 changed files with 331 additions and 378 deletions
|
|
@ -107,6 +107,10 @@ type UserNotifier interface {
|
|||
NotifyUserChanged(ctx context.Context, u domain.User) error
|
||||
}
|
||||
|
||||
type UserModerationNotifier interface {
|
||||
NotifyUserModerationFlagsChanged(ctx context.Context, u domain.User) error
|
||||
}
|
||||
|
||||
type AccountFreezeNotifier interface {
|
||||
NotifyAccountFreezeChanged(ctx context.Context, freeze domain.AccountFreeze) error
|
||||
}
|
||||
|
|
@ -184,47 +188,49 @@ type GiftGranter interface {
|
|||
}
|
||||
|
||||
type Dependencies struct {
|
||||
Commands CommandRepository
|
||||
Restrictions RestrictionStore
|
||||
Auth AuthService
|
||||
Revoker AuthKeyRevoker
|
||||
Users UsersService
|
||||
Stars StarsService
|
||||
StarsNotifier StarsNotifier
|
||||
UserNotifier UserNotifier
|
||||
FreezeNotifier AccountFreezeNotifier
|
||||
Channels ChannelsService
|
||||
ChannelNotifier ChannelNotifier
|
||||
Messages MessagesService
|
||||
Gifts GiftsService
|
||||
GiftGranter GiftGranter
|
||||
OfficialGifts OfficialGiftsSource
|
||||
Bots BotService
|
||||
Emoji EmojiService
|
||||
Moderation ModerationService
|
||||
Now func() time.Time
|
||||
Commands CommandRepository
|
||||
Restrictions RestrictionStore
|
||||
Auth AuthService
|
||||
Revoker AuthKeyRevoker
|
||||
Users UsersService
|
||||
Stars StarsService
|
||||
StarsNotifier StarsNotifier
|
||||
UserNotifier UserNotifier
|
||||
UserModerationNotifier UserModerationNotifier
|
||||
FreezeNotifier AccountFreezeNotifier
|
||||
Channels ChannelsService
|
||||
ChannelNotifier ChannelNotifier
|
||||
Messages MessagesService
|
||||
Gifts GiftsService
|
||||
GiftGranter GiftGranter
|
||||
OfficialGifts OfficialGiftsSource
|
||||
Bots BotService
|
||||
Emoji EmojiService
|
||||
Moderation ModerationService
|
||||
Now func() time.Time
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
commands CommandRepository
|
||||
restrictions RestrictionStore
|
||||
auth AuthService
|
||||
revoker AuthKeyRevoker
|
||||
users UsersService
|
||||
stars StarsService
|
||||
starsNotifier StarsNotifier
|
||||
userNotifier UserNotifier
|
||||
freezeNotifier AccountFreezeNotifier
|
||||
channels ChannelsService
|
||||
channelNotifier ChannelNotifier
|
||||
messages MessagesService
|
||||
gifts GiftsService
|
||||
giftGranter GiftGranter
|
||||
officialGifts OfficialGiftsSource
|
||||
bots BotService
|
||||
emoji EmojiService
|
||||
moderation ModerationService
|
||||
now func() time.Time
|
||||
commands CommandRepository
|
||||
restrictions RestrictionStore
|
||||
auth AuthService
|
||||
revoker AuthKeyRevoker
|
||||
users UsersService
|
||||
stars StarsService
|
||||
starsNotifier StarsNotifier
|
||||
userNotifier UserNotifier
|
||||
userModerationNotifier UserModerationNotifier
|
||||
freezeNotifier AccountFreezeNotifier
|
||||
channels ChannelsService
|
||||
channelNotifier ChannelNotifier
|
||||
messages MessagesService
|
||||
gifts GiftsService
|
||||
giftGranter GiftGranter
|
||||
officialGifts OfficialGiftsSource
|
||||
bots BotService
|
||||
emoji EmojiService
|
||||
moderation ModerationService
|
||||
now func() time.Time
|
||||
}
|
||||
|
||||
func NewService(deps Dependencies) *Service {
|
||||
|
|
@ -257,6 +263,9 @@ func (s *Service) Configure(deps Dependencies) *Service {
|
|||
if deps.UserNotifier != nil {
|
||||
s.userNotifier = deps.UserNotifier
|
||||
}
|
||||
if deps.UserModerationNotifier != nil {
|
||||
s.userModerationNotifier = deps.UserModerationNotifier
|
||||
}
|
||||
if deps.FreezeNotifier != nil {
|
||||
s.freezeNotifier = deps.FreezeNotifier
|
||||
}
|
||||
|
|
@ -969,7 +978,7 @@ func (s *Service) SetUserFlags(ctx context.Context, req SetUserFlagsRequest) (Co
|
|||
}
|
||||
details["updated_scam"] = updated.Scam
|
||||
details["updated_fake"] = updated.Fake
|
||||
if err := s.notifyUserChanged(ctx, updated); err != nil {
|
||||
if err := s.notifyUserModerationFlagsChanged(ctx, updated); err != nil {
|
||||
details["notify_error"] = err.Error()
|
||||
}
|
||||
return CommandResult{Message: "user flags updated", Details: details}, nil
|
||||
|
|
@ -2232,6 +2241,13 @@ func (s *Service) notifyUserChanged(ctx context.Context, u domain.User) error {
|
|||
return s.userNotifier.NotifyUserChanged(ctx, u)
|
||||
}
|
||||
|
||||
func (s *Service) notifyUserModerationFlagsChanged(ctx context.Context, u domain.User) error {
|
||||
if s == nil || s.userModerationNotifier == nil {
|
||||
return s.notifyUserChanged(ctx, u)
|
||||
}
|
||||
return s.userModerationNotifier.NotifyUserModerationFlagsChanged(ctx, u)
|
||||
}
|
||||
|
||||
func (s *Service) notifyAccountFreezeChanged(ctx context.Context, freeze domain.AccountFreeze) error {
|
||||
if s == nil || s.freezeNotifier == nil {
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -143,6 +143,39 @@ func TestModerationFlagsRejectImpossibleScamFakeState(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSetUserFlagsUsesNonPTSModerationNotifier(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
users := &fakeUsersService{users: map[int64]domain.User{
|
||||
1001: {ID: 1001, FirstName: "Alice"},
|
||||
}}
|
||||
ordinaryNotifier := &fakeUserNotifier{}
|
||||
moderationNotifier := &fakeUserModerationNotifier{}
|
||||
svc := NewService(Dependencies{
|
||||
Commands: newMemoryCommandRepo(),
|
||||
Users: users,
|
||||
UserNotifier: ordinaryNotifier,
|
||||
UserModerationNotifier: moderationNotifier,
|
||||
Now: fixedNow,
|
||||
})
|
||||
|
||||
if _, err := svc.SetUserFlags(ctx, SetUserFlagsRequest{
|
||||
CommandMeta: CommandMeta{CommandID: "set-user-scam", Actor: "ops", Reason: "confirmed report"},
|
||||
UserID: 1001,
|
||||
Scam: true,
|
||||
}); err != nil {
|
||||
t.Fatalf("SetUserFlags: %v", err)
|
||||
}
|
||||
if got := users.users[1001]; !got.Scam || got.Fake {
|
||||
t.Fatalf("updated user = %+v", got)
|
||||
}
|
||||
if len(moderationNotifier.users) != 1 || moderationNotifier.users[0] != 1001 {
|
||||
t.Fatalf("moderation notifications = %v", moderationNotifier.users)
|
||||
}
|
||||
if len(ordinaryNotifier.users) != 0 {
|
||||
t.Fatalf("ordinary notifications = %v, want dedicated non-PTS path", ordinaryNotifier.users)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountFreezesBatchesAndReturnsOnlyActiveFacts(t *testing.T) {
|
||||
now := fixedNow()
|
||||
store := &fakeBatchRestrictionStore{fakeRestrictionStore: fakeRestrictionStore{items: map[int64]domain.AccountFreeze{
|
||||
|
|
@ -863,6 +896,15 @@ func (f *fakeUserNotifier) NotifyUserChanged(_ context.Context, u domain.User) e
|
|||
return nil
|
||||
}
|
||||
|
||||
type fakeUserModerationNotifier struct {
|
||||
users []int64
|
||||
}
|
||||
|
||||
func (f *fakeUserModerationNotifier) NotifyUserModerationFlagsChanged(_ context.Context, u domain.User) error {
|
||||
f.users = append(f.users, u.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
type fakeChannelsService struct {
|
||||
channels map[int64]domain.Channel
|
||||
verifiedCalls int
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue