Skip to content

Commit

Permalink
also audit for list value deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal-Delange committed Apr 3, 2024
1 parent 48bbc08 commit 08db852
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
11 changes: 7 additions & 4 deletions mocks/custom_list_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,16 @@ func (cl *CustomListRepository) AddCustomListValue(
newCustomListId string,
userId *models.UserId,
) error {
args := cl.Called(exec, addCustomListValue)
args := cl.Called(ctx, exec, addCustomListValue, userId)
return args.Error(0)
}

func (cl *CustomListRepository) DeleteCustomListValue(ctx context.Context,
exec repositories.Executor, deleteCustomListValue models.DeleteCustomListValueInput,
func (cl *CustomListRepository) DeleteCustomListValue(
ctx context.Context,
exec repositories.Executor,
deleteCustomListValue models.DeleteCustomListValueInput,
userId *models.UserId,
) error {
args := cl.Called(exec, deleteCustomListValue)
args := cl.Called(ctx, exec, deleteCustomListValue, userId)
return args.Error(0)
}
14 changes: 13 additions & 1 deletion repositories/custom_list_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ type CustomListRepository interface {
newCustomListId string,
userId *models.UserId,
) error
DeleteCustomListValue(ctx context.Context, exec Executor, deleteCustomListValue models.DeleteCustomListValueInput) error
DeleteCustomListValue(
ctx context.Context,
exec Executor,
deleteCustomListValue models.DeleteCustomListValueInput,
userId *models.UserId,
) error
}

type CustomListRepositoryPostgresql struct{}
Expand Down Expand Up @@ -201,11 +206,18 @@ func (repo *CustomListRepositoryPostgresql) DeleteCustomListValue(
ctx context.Context,
exec Executor,
deleteCustomListValue models.DeleteCustomListValueInput,
userId *models.UserId,
) error {
if err := validateMarbleDbExecutor(exec); err != nil {
return err
}

if userId != nil {
if err := setCurrentUserIdContext(ctx, exec, userId); err != nil {
return err
}
}

deleteRequest := NewQueryBuilder().Update(dbmodels.TABLE_CUSTOM_LIST_VALUE)

deleteRequest = deleteRequest.Set("deleted_at", squirrel.Expr("NOW()"))
Expand Down
8 changes: 7 additions & 1 deletion usecases/custom_list_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ func (usecase *CustomListUseCase) AddCustomListValue(ctx context.Context,
func (usecase *CustomListUseCase) DeleteCustomListValue(ctx context.Context,
deleteCustomListValue models.DeleteCustomListValueInput,
) error {
var userId *models.UserId
creds, found := utils.CredentialsFromCtx(ctx)
if found {
userId = &creds.ActorIdentity.UserId
}

err := usecase.transactionFactory.Transaction(ctx, func(tx repositories.Executor) error {
customList, err := usecase.CustomListRepository.GetCustomListById(ctx, tx, deleteCustomListValue.CustomListId)
if err != nil {
Expand All @@ -201,7 +207,7 @@ func (usecase *CustomListUseCase) DeleteCustomListValue(ctx context.Context,
if err := usecase.enforceSecurity.ModifyCustomList(customList); err != nil {
return err
}
return usecase.CustomListRepository.DeleteCustomListValue(ctx, tx, deleteCustomListValue)
return usecase.CustomListRepository.DeleteCustomListValue(ctx, tx, deleteCustomListValue, userId)
})
if err != nil {
return err
Expand Down

0 comments on commit 08db852

Please sign in to comment.