This commit is contained in:
@@ -127,14 +127,17 @@ func accountIdentity(account *model.Account) map[string]any {
|
||||
func (w *Writer) WriteAccessChange(ctx context.Context, tx *gorm.DB, change accessauditapp.ChangeAudit) error {
|
||||
action, ok := w.registry.Action(change.ActionCode)
|
||||
if !ok {
|
||||
return pkgerrors.New(pkgerrors.CodeInvalidParam, "账号权限或组织审计动作未注册")
|
||||
recordBusinessWriteFailure(ctx, change.ActionCode, accessChangeResourceKey(change), pkgerrors.New(pkgerrors.CodeInvalidParam, "账号权限或组织审计动作未注册"))
|
||||
return nil
|
||||
}
|
||||
if change.OperatorID == 0 {
|
||||
return pkgerrors.New(pkgerrors.CodeInvalidParam, "账号权限或组织审计操作者不完整")
|
||||
recordBusinessWriteFailure(ctx, action.Code, accessChangeResourceKey(change), pkgerrors.New(pkgerrors.CodeInvalidParam, "账号权限或组织审计操作者不完整"))
|
||||
return nil
|
||||
}
|
||||
resources, err := accessResources(change, action.PrimaryResource)
|
||||
if err != nil {
|
||||
return err
|
||||
recordBusinessWriteFailure(ctx, action.Code, accessChangeResourceKey(change), err)
|
||||
return nil
|
||||
}
|
||||
result := change.Result
|
||||
if result == "" {
|
||||
@@ -166,6 +169,25 @@ func (w *Writer) WriteAccessChange(ctx context.Context, tx *gorm.DB, change acce
|
||||
})
|
||||
}
|
||||
|
||||
func accessChangeResourceKey(change accessauditapp.ChangeAudit) string {
|
||||
if change.PersonalCustomer != nil {
|
||||
return strconv.FormatUint(uint64(change.PersonalCustomer.ID), 10)
|
||||
}
|
||||
if change.Account != nil {
|
||||
return accountResourceKey(change.Account)
|
||||
}
|
||||
if change.Shop != nil {
|
||||
return shopResourceKey(change.Shop)
|
||||
}
|
||||
if change.Enterprise != nil {
|
||||
return enterpriseResourceKey(change.Enterprise)
|
||||
}
|
||||
if change.Role != nil {
|
||||
return strconv.FormatUint(uint64(change.Role.ID), 10)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func accessResources(change accessauditapp.ChangeAudit, primaryResource string) ([]ResourceInput, error) {
|
||||
resources := make([]ResourceInput, 0, 2+len(change.Accounts)+len(change.Cards)+len(change.CardAuthorizations)+len(change.Devices)+len(change.DeviceBindings)+len(change.DeviceAuthorizations)+len(change.PersonalPhones)+len(change.PersonalOpenIDs)+len(change.PersonalDevices)+len(change.PersonalICCIDs)+len(change.Roles)+len(change.Permissions))
|
||||
switch primaryResource {
|
||||
@@ -873,7 +895,10 @@ func (w *Writer) WriteRecovery(ctx context.Context, tx *gorm.DB, recovery outbox
|
||||
// Append 在调用方提供的 GORM 事务中顺序追加事件及资源。
|
||||
func (w *Writer) Append(ctx context.Context, tx *gorm.DB, input AppendInput) error {
|
||||
_, err := w.AppendAndGet(ctx, tx, input)
|
||||
return err
|
||||
if err != nil {
|
||||
recordBusinessAppendFailure(ctx, input, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AppendAndGet 追加事件并返回已持久化的审计事件,幂等重放返回已有事件。
|
||||
|
||||
Reference in New Issue
Block a user