2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-08-22 02:02:14 +00:00

only save changes made or errors

This commit is contained in:
Aravindh-Raju 2024-10-14 13:37:15 +05:30
parent 93ceee7e15
commit 3fe6b91942
No known key found for this signature in database
GPG Key ID: 6B4D566AC36626F6
4 changed files with 26 additions and 11 deletions

View File

@ -28,6 +28,7 @@ import vinyldns.api.domain.batch.BatchChangeInterfaces._
import vinyldns.api.domain.batch.BatchTransformations._ import vinyldns.api.domain.batch.BatchTransformations._
import vinyldns.api.domain.zone.ZoneRecordValidations.isStringInRegexList import vinyldns.api.domain.zone.ZoneRecordValidations.isStringInRegexList
import vinyldns.api.domain.zone.ZoneRecordValidations import vinyldns.api.domain.zone.ZoneRecordValidations
import vinyldns.core.Messages.{nonExistentRecordDataDeleteMessage, nonExistentRecordDeleteMessage}
import vinyldns.core.domain.DomainHelpers.omitTrailingDot import vinyldns.core.domain.DomainHelpers.omitTrailingDot
import vinyldns.core.domain.record._ import vinyldns.core.domain.record._
import vinyldns.core.domain._ import vinyldns.core.domain._
@ -350,9 +351,6 @@ class BatchChangeValidations(
isApproved: Boolean isApproved: Boolean
): SingleValidation[ChangeForValidation] = { ): SingleValidation[ChangeForValidation] = {
val nonExistentRecordDeleteMessage = "This record does not exist. No further action is required."
val nonExistentRecordDataDeleteMessage = "Record data entered does not exist. No further action is required."
val recordData = change match { val recordData = change match {
case AddChangeForValidation(_, _, inputChange, _, _) => inputChange.record.toString case AddChangeForValidation(_, _, inputChange, _, _) => inputChange.record.toString
case DeleteRRSetChangeForValidation(_, _, inputChange) => inputChange.record.map(_.toString).getOrElse("") case DeleteRRSetChangeForValidation(_, _, inputChange) => inputChange.record.map(_.toString).getOrElse("")
@ -425,9 +423,6 @@ class BatchChangeValidations(
isApproved: Boolean isApproved: Boolean
): SingleValidation[ChangeForValidation] = { ): SingleValidation[ChangeForValidation] = {
val nonExistentRecordDeleteMessage = "This record does not exist. No further action is required."
val nonExistentRecordDataDeleteMessage = "Record data entered does not exist. No further action is required."
// To handle add and delete for the record with same record data is present in the batch // To handle add and delete for the record with same record data is present in the batch
val recordData = change match { val recordData = change match {
case AddChangeForValidation(_, _, inputChange, _, _) => inputChange.record.toString case AddChangeForValidation(_, _, inputChange, _, _) => inputChange.record.toString

View File

@ -23,6 +23,7 @@ import scalikejdbc.DB
import vinyldns.api.backend.dns.DnsProtocol.TryAgain import vinyldns.api.backend.dns.DnsProtocol.TryAgain
import vinyldns.api.domain.record.RecordSetChangeGenerator import vinyldns.api.domain.record.RecordSetChangeGenerator
import vinyldns.api.domain.record.RecordSetHelpers._ import vinyldns.api.domain.record.RecordSetHelpers._
import vinyldns.core.Messages.{nonExistentRecordDataDeleteMessage, nonExistentRecordDeleteMessage}
import vinyldns.core.domain.backend.{Backend, BackendResponse} import vinyldns.core.domain.backend.{Backend, BackendResponse}
import vinyldns.core.domain.batch.{BatchChangeRepository, SingleChange} import vinyldns.core.domain.batch.{BatchChangeRepository, SingleChange}
import vinyldns.core.domain.record._ import vinyldns.core.domain.record._
@ -92,15 +93,31 @@ object RecordSetChangeHandler extends TransactionProvider {
): IO[Unit] = ): IO[Unit] =
executeWithinTransaction { db: DB => executeWithinTransaction { db: DB =>
for { for {
_ <- recordSetRepository.apply(db, changeSet)
_ <- recordChangeRepository.save(db, changeSet)
_ <- recordSetCacheRepository.save(db, changeSet)
// Update single changes within this transaction to rollback the changes made to recordset and record change repo // Update single changes within this transaction to rollback the changes made to recordset and record change repo
// when exception occurs while updating single changes // when exception occurs while updating single changes
singleBatchChanges <- batchChangeRepository.getSingleChanges( singleBatchChanges <- batchChangeRepository.getSingleChanges(
recordSetChange.singleBatchChangeIds recordSetChange.singleBatchChangeIds
) )
singleChangeStatusUpdates = updateBatchStatuses(singleBatchChanges, completedState.change) singleChangeStatusUpdates = updateBatchStatuses(singleBatchChanges, completedState.change)
updatedChangeSet = if (singleChangeStatusUpdates.size == 1) {
// Filter out RecordSetChange from changeSet if systemMessage matches
val filteredChangeSetChanges = changeSet.changes.filterNot { recordSetChange =>
// Find the corresponding singleChangeStatusUpdate by recordChangeId
singleChangeStatusUpdates.exists { singleChange =>
singleChange.recordChangeId.contains(recordSetChange.id) &&
singleChange.systemMessage.exists(msg =>
msg == nonExistentRecordDeleteMessage || msg == nonExistentRecordDataDeleteMessage
)
}
}
// Create a new ChangeSet with filtered changes
changeSet.copy(changes = filteredChangeSetChanges)
} else {
changeSet
}
_ <- recordSetRepository.apply(db, updatedChangeSet)
_ <- recordChangeRepository.save(db, updatedChangeSet)
_ <- recordSetCacheRepository.save(db, updatedChangeSet)
_ <- batchChangeRepository.updateSingleChanges(singleChangeStatusUpdates) _ <- batchChangeRepository.updateSingleChanges(singleChangeStatusUpdates)
} yield () } yield ()
} }

View File

@ -26,6 +26,7 @@ import vinyldns.api.domain.batch.BatchTransformations._
import vinyldns.api.domain.batch.BatchTransformations.LogicalChangeType._ import vinyldns.api.domain.batch.BatchTransformations.LogicalChangeType._
import vinyldns.api.engine.TestMessageQueue import vinyldns.api.engine.TestMessageQueue
import vinyldns.api.repository._ import vinyldns.api.repository._
import vinyldns.core.Messages.nonExistentRecordDeleteMessage
import vinyldns.core.TestMembershipData.okUser import vinyldns.core.TestMembershipData.okUser
import vinyldns.core.TestRecordSetData._ import vinyldns.core.TestRecordSetData._
import vinyldns.core.TestZoneData.{okZone, _} import vinyldns.core.TestZoneData.{okZone, _}
@ -37,8 +38,6 @@ import vinyldns.core.domain.record._
import vinyldns.core.domain.zone.Zone import vinyldns.core.domain.zone.Zone
class BatchChangeConverterSpec extends AnyWordSpec with Matchers { class BatchChangeConverterSpec extends AnyWordSpec with Matchers {
private val nonExistentRecordDeleteMessage: String = "This record does not exist. " +
"No further action is required."
private def makeSingleAddChange( private def makeSingleAddChange(
name: String, name: String,

View File

@ -84,4 +84,8 @@ object Messages {
val InvalidEmailValidationErrorMsg = "Please enter a valid Email." val InvalidEmailValidationErrorMsg = "Please enter a valid Email."
val DotsValidationErrorMsg = "Please enter a valid Email. Number of dots allowed after @ is" val DotsValidationErrorMsg = "Please enter a valid Email. Number of dots allowed after @ is"
val nonExistentRecordDeleteMessage = "This record does not exist. No further action is required."
val nonExistentRecordDataDeleteMessage = "Record data entered does not exist. No further action is required."
} }