diff --git a/internal/dataagreement/dataagreements.go b/internal/dataagreement/dataagreements.go index bc776df..9741529 100644 --- a/internal/dataagreement/dataagreements.go +++ b/internal/dataagreement/dataagreements.go @@ -42,6 +42,12 @@ type Signature struct { ObjectReference string `json:"objectReference"` } +type Controller struct { + Id string `json:"id"` + Name string `json:"name"` + Url string `json:"url"` +} + type DataAgreement struct { Id string `json:"id" bson:"_id,omitempty"` Version string `json:"version"` @@ -52,7 +58,7 @@ type DataAgreement struct { Purpose string `json:"purpose" valid:"required"` PurposeDescription string `json:"purposeDescription" valid:"required"` LawfulBasis string `json:"lawfulBasis" valid:"required"` - MethodOfUse string `json:"methodOfUse" valid:"required"` + MethodOfUse string `json:"methodOfUse"` DpiaDate string `json:"dpiaDate"` DpiaSummaryUrl string `json:"dpiaSummaryUrl"` Signature Signature `json:"signature"` @@ -64,6 +70,10 @@ type DataAgreement struct { OrganisationId string `json:"-"` IsDeleted bool `json:"-"` Timestamp string `json:"-"` + DataUse string `json:"dataUse"` + Dpia string `json:"dpia"` + CompatibleWithVersion string `json:"compatibleWithVersion"` + Controller Controller `json:"controller"` } type DataAgreementWithObjectData struct { @@ -118,16 +128,12 @@ func (darepo *DataAgreementRepository) Update(dataAgreement DataAgreement) (Data } // IsDataAgreementExist Check if data agreement with given id exists -func (darepo *DataAgreementRepository) IsDataAgreementExist(dataAgreementID string) (int64, error) { +func (darepo *DataAgreementRepository) IsDataAgreementExist(dataAgreementId string) (int64, error) { var exists int64 - dataAgreementId, err := primitive.ObjectIDFromHex(dataAgreementID) - if err != nil { - return exists, err - } filter := common.CombineFilters(darepo.DefaultFilter, bson.M{"_id": dataAgreementId}) - exists, err = Collection().CountDocuments(context.TODO(), filter) + exists, err := Collection().CountDocuments(context.TODO(), filter) if err != nil { return exists, err } diff --git a/internal/handler/v2/config/dataagreement/config_create_dataagreement.go b/internal/handler/v2/config/dataagreement/config_create_dataagreement.go index 08d24ad..6ecbedf 100644 --- a/internal/handler/v2/config/dataagreement/config_create_dataagreement.go +++ b/internal/handler/v2/config/dataagreement/config_create_dataagreement.go @@ -87,7 +87,7 @@ type dataAgreement struct { Purpose string `json:"purpose" validate:"required_if=Active true"` PurposeDescription string `json:"purposeDescription" validate:"required_if=Active true,max=500"` LawfulBasis string `json:"lawfulBasis" validate:"required_if=Active true"` - MethodOfUse string `json:"methodOfUse" validate:"required_if=Active true"` + MethodOfUse string `json:"methodOfUse"` DpiaDate string `json:"dpiaDate"` DpiaSummaryUrl string `json:"dpiaSummaryUrl"` Signature dataagreement.Signature `json:"signature"` @@ -98,6 +98,10 @@ type dataAgreement struct { DataAttributes []dataAttributeForDataAgreement `json:"dataAttributes" validate:"required_if=Active true"` OrganisationId string `json:"-"` IsDeleted bool `json:"-"` + DataUse string `json:"dataUse"` + Dpia string `json:"dpia"` + CompatibleWithVersion string `json:"compatibleWithVersion"` + Controller dataagreement.Controller `json:"controller"` } type addDataAgreementReq struct { @@ -147,11 +151,18 @@ func validateAddDataAgreementRequestBody(dataAgreementReq addDataAgreementReq) e return errors.New("invalid lawful basis provided") } - // Proceed if method of use is valid - if !isValidMethodOfUse(dataAgreementReq.DataAgreement.MethodOfUse) { + if len(strings.TrimSpace(dataAgreementReq.DataAgreement.DataUse)) < 1 && len(strings.TrimSpace(dataAgreementReq.DataAgreement.MethodOfUse)) < 1 { + return errors.New("missing mandatory param dataUse") + } + + if len(strings.TrimSpace(dataAgreementReq.DataAgreement.MethodOfUse)) > 1 && !isValidMethodOfUse(dataAgreementReq.DataAgreement.MethodOfUse) { return errors.New("invalid method of use provided") } + if len(strings.TrimSpace(dataAgreementReq.DataAgreement.DataUse)) > 1 && !isValidMethodOfUse(dataAgreementReq.DataAgreement.DataUse) { + return errors.New("invalid data use provided") + } + return nil } @@ -222,8 +233,19 @@ func setDataAgreementFromReq(requestBody addDataAgreementReq, newDataAgreement d newDataAgreement.Forgettable = requestBody.DataAgreement.Forgettable newDataAgreement.CompatibleWithVersionId = requestBody.DataAgreement.CompatibleWithVersionId newDataAgreement.DataAttributes = setDataAttributesFromReq(requestBody) + newDataAgreement.Dpia = requestBody.DataAgreement.Dpia + newDataAgreement.CompatibleWithVersion = requestBody.DataAgreement.CompatibleWithVersion + newDataAgreement.Lifecycle = setDataAgreementLifecycle(requestBody.DataAgreement.Active) + // update method of use if data use not empty and is valid + if len(strings.TrimSpace(requestBody.DataAgreement.DataUse)) > 0 && isValidMethodOfUse(requestBody.DataAgreement.DataUse) { + newDataAgreement.DataUse = requestBody.DataAgreement.DataUse + newDataAgreement.MethodOfUse = requestBody.DataAgreement.DataUse + } else { + newDataAgreement.DataUse = requestBody.DataAgreement.MethodOfUse + } + return newDataAgreement } @@ -232,6 +254,10 @@ func setControllerFromReq(o org.Organization, newDataAgreement dataagreement.Dat newDataAgreement.ControllerId = o.ID newDataAgreement.ControllerName = o.Name newDataAgreement.ControllerUrl = o.EulaURL + + newDataAgreement.Controller.Id = o.ID + newDataAgreement.Controller.Name = o.Name + newDataAgreement.Controller.Url = o.EulaURL return newDataAgreement } diff --git a/internal/handler/v2/config/dataagreement/config_list_dataagreements.go b/internal/handler/v2/config/dataagreement/config_list_dataagreements.go index bf845da..049315b 100644 --- a/internal/handler/v2/config/dataagreement/config_list_dataagreements.go +++ b/internal/handler/v2/config/dataagreement/config_list_dataagreements.go @@ -158,6 +158,10 @@ func setDataAgreementWithRevisions(dataAgreement dataagreement.DataAgreement, re dataAgreementWithRevision.ControllerUrl = dataAgreement.ControllerUrl dataAgreementWithRevision.Version = dataAgreement.Version dataAgreementWithRevision.Revisions = revisions + dataAgreementWithRevision.Controller = dataAgreement.Controller + dataAgreementWithRevision.Dpia = dataAgreement.Dpia + dataAgreementWithRevision.DataUse = dataAgreement.DataUse + dataAgreementWithRevision.CompatibleWithVersion = dataAgreement.CompatibleWithVersion return dataAgreementWithRevision } @@ -236,6 +240,10 @@ type dataAgreementWithRevisions struct { IsDeleted bool `json:"-"` Timestamp string `json:"-"` Revisions []revision.Revision `json:"revisions"` + DataUse string `json:"dataUse"` + Dpia string `json:"dpia"` + CompatibleWithVersion string `json:"compatibleWithVersion"` + Controller dataagreement.Controller `json:"controller"` } func dataAgreementsWithRevisionsToInterfaceSlice(dataAgreements []dataAgreementWithRevisions) []interface{} { diff --git a/internal/handler/v2/config/dataagreement/config_update_dataagreement.go b/internal/handler/v2/config/dataagreement/config_update_dataagreement.go index 7279d02..a805ba2 100644 --- a/internal/handler/v2/config/dataagreement/config_update_dataagreement.go +++ b/internal/handler/v2/config/dataagreement/config_update_dataagreement.go @@ -41,11 +41,18 @@ func validateUpdateDataAgreementRequestBody(dataAgreementReq updateDataAgreement return errors.New("invalid lawful basis provided") } - // Proceed if method of use is valid - if !isValidMethodOfUse(dataAgreementReq.DataAgreement.MethodOfUse) { + if len(strings.TrimSpace(dataAgreementReq.DataAgreement.DataUse)) < 1 && len(strings.TrimSpace(dataAgreementReq.DataAgreement.MethodOfUse)) < 1 { + return errors.New("missing mandatory param dataUse") + } + + if len(strings.TrimSpace(dataAgreementReq.DataAgreement.MethodOfUse)) > 1 && !isValidMethodOfUse(dataAgreementReq.DataAgreement.MethodOfUse) { return errors.New("invalid method of use provided") } + if len(strings.TrimSpace(dataAgreementReq.DataAgreement.DataUse)) > 1 && !isValidMethodOfUse(dataAgreementReq.DataAgreement.DataUse) { + return errors.New("invalid data use provided") + } + return nil } @@ -82,6 +89,17 @@ func updateDataAttributeFromUpdateDataAgreementRequestBody(requestBody updateDat return newDataAttributes } +func updateControllerFromReq(o org.Organization, toBeUpdatedDataAgreement dataagreement.DataAgreement) dataagreement.DataAgreement { + toBeUpdatedDataAgreement.ControllerId = o.ID + toBeUpdatedDataAgreement.ControllerName = o.Name + toBeUpdatedDataAgreement.ControllerUrl = o.EulaURL + + toBeUpdatedDataAgreement.Controller.Id = o.ID + toBeUpdatedDataAgreement.Controller.Name = o.Name + toBeUpdatedDataAgreement.Controller.Url = o.EulaURL + return toBeUpdatedDataAgreement +} + func updateDataAgreementFromRequestBody(requestBody updateDataAgreementReq, toBeUpdatedDataAgreement dataagreement.DataAgreement) dataagreement.DataAgreement { toBeUpdatedDataAgreement.Policy.Name = requestBody.DataAgreement.Policy.Name @@ -100,6 +118,8 @@ func updateDataAgreementFromRequestBody(requestBody updateDataAgreementReq, toBe toBeUpdatedDataAgreement.MethodOfUse = requestBody.DataAgreement.MethodOfUse toBeUpdatedDataAgreement.DpiaDate = requestBody.DataAgreement.DpiaDate toBeUpdatedDataAgreement.DpiaSummaryUrl = requestBody.DataAgreement.DpiaSummaryUrl + toBeUpdatedDataAgreement.Dpia = requestBody.DataAgreement.Dpia + toBeUpdatedDataAgreement.CompatibleWithVersion = requestBody.DataAgreement.CompatibleWithVersion toBeUpdatedDataAgreement.Signature.Payload = requestBody.DataAgreement.Signature.Payload toBeUpdatedDataAgreement.Signature.Signature = requestBody.DataAgreement.Signature.Signature @@ -126,6 +146,14 @@ func updateDataAgreementFromRequestBody(requestBody updateDataAgreementReq, toBe toBeUpdatedDataAgreement.DataAttributes = dataAttributes + // update method of use if data use not empty and is valid + if len(strings.TrimSpace(requestBody.DataAgreement.DataUse)) > 0 && isValidMethodOfUse(requestBody.DataAgreement.DataUse) { + toBeUpdatedDataAgreement.DataUse = requestBody.DataAgreement.DataUse + toBeUpdatedDataAgreement.MethodOfUse = requestBody.DataAgreement.DataUse + } else { + toBeUpdatedDataAgreement.DataUse = requestBody.DataAgreement.MethodOfUse + } + return toBeUpdatedDataAgreement } @@ -156,7 +184,7 @@ func ConfigUpdateDataAgreement(w http.ResponseWriter, r *http.Request) { } // Query organisation by Id - _, err = org.Get(organisationId) + o, err := org.Get(organisationId) if err != nil { m := fmt.Sprintf("Failed to get organization by ID :%v", organisationId) common.HandleErrorV2(w, http.StatusNotFound, m, err) @@ -192,6 +220,7 @@ func ConfigUpdateDataAgreement(w http.ResponseWriter, r *http.Request) { // Update data agreement from request body toBeUpdatedDataAgreement := updateDataAgreementFromRequestBody(dataAgreementReq, currentDataAgreement) + toBeUpdatedDataAgreement = updateControllerFromReq(o, toBeUpdatedDataAgreement) // Bump major version for data agreement updatedVersion, err := common.BumpMajorVersion(toBeUpdatedDataAgreement.Version) diff --git a/internal/revision/revisions.go b/internal/revision/revisions.go index 96e1480..dc712d2 100644 --- a/internal/revision/revisions.go +++ b/internal/revision/revisions.go @@ -258,6 +258,10 @@ type dataAgreementForObjectData struct { DataAttributes []dataagreement.DataAttribute `json:"dataAttributes" valid:"required"` OrganisationId string `json:"-"` IsDeleted bool `json:"-"` + DataUse string `json:"dataUse"` + Dpia string `json:"dpia"` + CompatibleWithVersion string `json:"compatibleWithVersion"` + Controller dataagreement.Controller `json:"controller"` } // InitForDraftDataAgreement @@ -292,6 +296,11 @@ func CreateRevisionForDataAgreement(newDataAgreement dataagreement.DataAgreement CompatibleWithVersionId: newDataAgreement.CompatibleWithVersionId, Lifecycle: newDataAgreement.Lifecycle, DataAttributes: newDataAgreement.DataAttributes, + DataUse: newDataAgreement.DataUse, + Dpia: newDataAgreement.Dpia, + CompatibleWithVersion: newDataAgreement.CompatibleWithVersion, + ControllerName: newDataAgreement.ControllerName, + Controller: newDataAgreement.Controller, } // Create revision @@ -323,6 +332,11 @@ func UpdateRevisionForDataAgreement(updatedDataAgreement dataagreement.DataAgree CompatibleWithVersionId: updatedDataAgreement.CompatibleWithVersionId, Lifecycle: updatedDataAgreement.Lifecycle, DataAttributes: updatedDataAgreement.DataAttributes, + DataUse: updatedDataAgreement.DataUse, + Dpia: updatedDataAgreement.Dpia, + CompatibleWithVersion: updatedDataAgreement.CompatibleWithVersion, + ControllerName: updatedDataAgreement.ControllerName, + Controller: updatedDataAgreement.Controller, } // Initialise revision @@ -400,6 +414,11 @@ func CreateRevisionForDraftDataAgreement(newDataAgreement dataagreement.DataAgre CompatibleWithVersionId: newDataAgreement.CompatibleWithVersionId, Lifecycle: newDataAgreement.Lifecycle, DataAttributes: newDataAgreement.DataAttributes, + DataUse: newDataAgreement.DataUse, + Dpia: newDataAgreement.Dpia, + CompatibleWithVersion: newDataAgreement.CompatibleWithVersion, + ControllerName: newDataAgreement.ControllerName, + Controller: newDataAgreement.Controller, } // Create revision diff --git a/resources/config b/resources/config index e8f8ccd..c052ed6 160000 --- a/resources/config +++ b/resources/config @@ -1 +1 @@ -Subproject commit e8f8ccdff8732dcf0f648598f9ed238185226da8 +Subproject commit c052ed6bebeac16555ece540396ac23774c40283