Skip to content

Commit

Permalink
Fix #407 Do NOT delete consent records when data agreement is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
albinpa authored and georgepadayatti committed Oct 31, 2023
1 parent 1963ab4 commit 0622d4f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 35 deletions.
16 changes: 0 additions & 16 deletions internal/dataagreement_record/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,6 @@ func CreatePipelineForFilteringDataAgreementRecords(organisationId string, id st
return pipeline, nil
}

// Deletes all the data agreement records for data agreement id
func (darRepo *DataAgreementRecordRepository) DeleteDataAgreementRecordsForDataAgreement(dataAgreementId string) error {
filter := common.CombineFilters(darRepo.DefaultFilter, bson.M{"dataagreementid": dataAgreementId})

// Update to set IsDeleted to true
update := bson.M{
"$set": bson.M{
"isdeleted": true,
},
}

_, err := Collection().UpdateMany(context.TODO(), filter, update)

return err
}

// CreatePipelineForFilteringLatestDataAgreementRecords This pipeline is used for filtering data agreement records
func CreatePipelineForFilteringLatestDataAgreementRecords(organisationId string) ([]primitive.M, error) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ func ConfigDeleteDataAgreement(w http.ResponseWriter, r *http.Request) {
darRepo := daRecord.DataAgreementRecordRepository{}
darRepo.Init(organisationId)

// Deletes all the data agreement records for data agreement id
err = darRepo.DeleteDataAgreementRecordsForDataAgreement(dataAgreementId)
if err != nil {
m := fmt.Sprintf("Failed to delete data agreement id from data agreement records: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}

_, err = daRepo.Update(currentDataAgreement)
if err != nil {
m := fmt.Sprintf("Failed to delete data agreement: %v", dataAgreementId)
Expand Down
22 changes: 11 additions & 11 deletions internal/handler/v2/service/service_update_dataagreement_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ func ServiceUpdateDataAgreementRecord(w http.ResponseWriter, r *http.Request) {
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}
// Repository
daRepo := dataagreement.DataAgreementRepository{}
daRepo.Init(organisationId)

da, err := daRepo.Get(dataAgreementId)
if err != nil {
m := fmt.Sprintf("Failed to fetch data agreement: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}

// Repository
darRepo := daRecord.DataAgreementRecordRepository{}
darRepo.Init(organisationId)
Expand Down Expand Up @@ -104,17 +115,6 @@ func ServiceUpdateDataAgreementRecord(w http.ResponseWriter, r *http.Request) {
return
}

// Repository
daRepo := dataagreement.DataAgreementRepository{}
daRepo.Init(organisationId)

da, err := daRepo.Get(dataAgreementId)
if err != nil {
m := fmt.Sprintf("Failed to fetch data agreement: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}

// Trigger webhooks
var consentedAttributes []string
for _, pConsent := range da.DataAttributes {
Expand Down

0 comments on commit 0622d4f

Please sign in to comment.