Skip to content

Commit

Permalink
Fix #631: Ability to configure data sources when defining data agreement
Browse files Browse the repository at this point in the history
  • Loading branch information
albinpa committed Sep 25, 2024
1 parent 89170c2 commit fb1b126
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/dataagreement/dataagreements.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ type Controller struct {
Url string `json:"url"`
}

type DataSource struct {
Name string `json:"name" validate:"required"`
Sector string `json:"sector" validate:"required"`
Location string `json:"location" validate:"required"`
PrivacyDashboardUrl string `json:"privacyDashboardUrl"`
}

type DataAgreement struct {
Id string `json:"id" bson:"_id,omitempty"`
Version string `json:"version"`
Expand All @@ -75,6 +82,7 @@ type DataAgreement struct {
Dpia string `json:"dpia"`
CompatibleWithVersion string `json:"compatibleWithVersion"`
Controller Controller `json:"controller"`
DataSources []DataSource `json:"dataSources"`
}

type DataAgreementWithObjectData struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type dataAgreement struct {
Dpia string `json:"dpia"`
CompatibleWithVersion string `json:"compatibleWithVersion"`
Controller dataagreement.Controller `json:"controller"`
DataSources []dataagreement.DataSource `json:"dataSources"`
}

type addDataAgreementReq struct {
Expand Down Expand Up @@ -163,6 +164,14 @@ func validateAddDataAgreementRequestBody(dataAgreementReq addDataAgreementReq) e
return errors.New("invalid data use provided")
}

if strings.TrimSpace(dataAgreementReq.DataAgreement.DataUse) == "data_using_service" || strings.TrimSpace(dataAgreementReq.DataAgreement.MethodOfUse) == "data_using_service" {
for _, dataSource := range dataAgreementReq.DataAgreement.DataSources {
if err := validate.Struct(dataSource); err != nil {
return err
}
}
}

return nil
}

Expand All @@ -176,6 +185,22 @@ func setDataAgreementLifecycle(active bool) string {
return lifecycle
}

func setDataAgreementDusDataSource(dataSourcesReq []dataagreement.DataSource) []dataagreement.DataSource {
dataSources := []dataagreement.DataSource{}

for _, dataSource := range dataSourcesReq {
var tempDataSource dataagreement.DataSource

tempDataSource.Name = dataSource.Name
tempDataSource.Sector = dataSource.Sector
tempDataSource.Location = dataSource.Location
tempDataSource.PrivacyDashboardUrl = dataSource.PrivacyDashboardUrl
dataSources = append(dataSources, tempDataSource)

}
return dataSources
}

func setDataAttributesFromReq(requestBody addDataAgreementReq) []dataagreement.DataAttribute {
var newDataAttributes []dataagreement.DataAttribute

Expand Down Expand Up @@ -246,6 +271,13 @@ func setDataAgreementFromReq(requestBody addDataAgreementReq, newDataAgreement d
newDataAgreement.DataUse = requestBody.DataAgreement.MethodOfUse
}

if newDataAgreement.DataUse == "data_using_service" {
dataSources := setDataAgreementDusDataSource(requestBody.DataAgreement.DataSources)
newDataAgreement.DataSources = dataSources
} else {
newDataAgreement.DataSources = []dataagreement.DataSource{}
}

return newDataAgreement
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func validateUpdateDataAgreementRequestBody(dataAgreementReq updateDataAgreement
return errors.New("invalid data use provided")
}

if strings.TrimSpace(dataAgreementReq.DataAgreement.DataUse) == "data_using_service" || strings.TrimSpace(dataAgreementReq.DataAgreement.MethodOfUse) == "data_using_service" {
for _, dataSource := range dataAgreementReq.DataAgreement.DataSources {
if err := validate.Struct(dataSource); err != nil {
return err
}
}
}

return nil
}

Expand Down Expand Up @@ -154,6 +162,14 @@ func updateDataAgreementFromRequestBody(requestBody updateDataAgreementReq, toBe
toBeUpdatedDataAgreement.DataUse = requestBody.DataAgreement.MethodOfUse
}

if toBeUpdatedDataAgreement.DataUse == "data_using_service" {
dataSources := setDataAgreementDusDataSource(requestBody.DataAgreement.DataSources)
toBeUpdatedDataAgreement.DataSources = dataSources
} else {
dataSources := []dataagreement.DataSource{}
toBeUpdatedDataAgreement.DataSources = dataSources
}

return toBeUpdatedDataAgreement
}

Expand Down
4 changes: 4 additions & 0 deletions internal/revision/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ type dataAgreementForObjectData struct {
Dpia string `json:"dpia"`
CompatibleWithVersion string `json:"compatibleWithVersion"`
Controller dataagreement.Controller `json:"controller"`
DataSources []dataagreement.DataSource `json:"dataSources"`
}

// InitForDraftDataAgreement
Expand Down Expand Up @@ -317,6 +318,7 @@ func CreateRevisionForDataAgreement(newDataAgreement dataagreement.DataAgreement
CompatibleWithVersion: newDataAgreement.CompatibleWithVersion,
ControllerName: newDataAgreement.ControllerName,
Controller: newDataAgreement.Controller,
DataSources: newDataAgreement.DataSources,
}

// Create revision
Expand Down Expand Up @@ -353,6 +355,7 @@ func UpdateRevisionForDataAgreement(updatedDataAgreement dataagreement.DataAgree
CompatibleWithVersion: updatedDataAgreement.CompatibleWithVersion,
ControllerName: updatedDataAgreement.ControllerName,
Controller: updatedDataAgreement.Controller,
DataSources: updatedDataAgreement.DataSources,
}

// Initialise revision
Expand Down Expand Up @@ -435,6 +438,7 @@ func CreateRevisionForDraftDataAgreement(newDataAgreement dataagreement.DataAgre
CompatibleWithVersion: newDataAgreement.CompatibleWithVersion,
ControllerName: newDataAgreement.ControllerName,
Controller: newDataAgreement.Controller,
DataSources: newDataAgreement.DataSources,
}

// Create revision
Expand Down

0 comments on commit fb1b126

Please sign in to comment.