From 0c658c512c8f98ea1fe66507ce531ace7d520b3d Mon Sep 17 00:00:00 2001 From: stremovsky Date: Wed, 25 Dec 2019 14:25:12 +0200 Subject: [PATCH] Add additional consent fields --- API.md | 12 +++++----- src/consent_api.go | 30 ++++++++++++++++++++++-- src/consent_db.go | 57 +++++++++++++++++++++++++++------------------- src/qldb.go | 4 ++++ 4 files changed, 72 insertions(+), 31 deletions(-) diff --git a/API.md b/API.md index 0ffdff6..7226e5c 100644 --- a/API.md +++ b/API.md @@ -329,14 +329,14 @@ POST Body can contain regular form data or JSON. Here is a table with list of ex | Parameter (required) | Description | | --------------------- | ------------------------------------------------------------------------------ | | status (no) | Consent status. Default value is **accept**. Allowed values: cancel/accept. | -| freetext (no) | Free text, used to internal usage. | | message (no) | Text message describing consent. If empty **brief** is displayed. | -| expiration (no) | Consent expiration date. It is be in UNIX time formar for like 10d or 1m. | +| freetext (no) | Free text, used for internal usage. | +| starttime (no) | Date & time to automatically enable this consent. It is in UNIX time format. | +| expiration (no) | Consent expiration date. It is in UNIX time format or kind of 10d or 1m, etc...| | lawfulbasis (no) | Default is **consent**. It can be: **contract-agreement**, **legal-obligations**, etc...| -| consentmethod (no) | Default is **api**. It can be: **phone-consent**, **contract**, **app-consent**, etc...| -| referencecode (no) | This can be used as an id of your internal document, contract, etc. | -| lastmodifiedby (no) | Name of the person that last modified this consnet or **customer**. | -| lastmodifieddate (no) | Date of the last modification. | +| consentmethod (no) | Default is **api**. It can be: **phone-consent**, **contract**, **app-consent**, **web-consent**, **email-consent**, etc...| +| referencecode (no) | This can be used as an id of your internal document, contract, etc... | +| lastmodifiedby (no) | Name of the person that last modified this record or **customer**. | When consent is expired, the status value is changed to **expired**. diff --git a/src/consent_api.go b/src/consent_api.go index 837eca1..157ce8e 100644 --- a/src/consent_api.go +++ b/src/consent_api.go @@ -64,17 +64,25 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro //returnError(w, r, "internal error", 405, err, event) return } + status := "accept" message := "" + freetext := "" lawfulbasis := "" consentmethod := "" referencecode := "" - status := "accept" + lastmodifiedby := "" + starttime := int32(0) expiration := int32(0) if value, ok := records["message"]; ok { if reflect.TypeOf(value) == reflect.TypeOf("string") { message = value.(string) } } + if value, ok := records["freetext"]; ok { + if reflect.TypeOf(value) == reflect.TypeOf("string") { + freetext = value.(string) + } + } if value, ok := records["lawfulbasis"]; ok { if reflect.TypeOf(value) == reflect.TypeOf("string") { lawfulbasis = value.(string) @@ -90,6 +98,11 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro referencecode = value.(string) } } + if value, ok := records["lastmodifiedby"]; ok { + if reflect.TypeOf(value) == reflect.TypeOf("string") { + lastmodifiedby = value.(string) + } + } if value, ok := records["status"]; ok { if reflect.TypeOf(value) == reflect.TypeOf("string") { status = value.(string) @@ -107,13 +120,26 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro expiration = value.(int32) } } + if value, ok := records["starttime"]; ok { + switch records["starttime"].(type) { + case string: + starttime, _ = parseExpiration(value.(string)) + case int: + starttime = value.(int32) + case int32: + starttime = value.(int32) + case int64: + starttime = value.(int32) + } + } switch mode { case "email": address = normalizeEmail(address) case "phone": address = normalizePhone(address, e.conf.Sms.Default_country) } - e.db.createConsentRecord(userTOKEN, mode, address, brief, message, status, lawfulbasis, consentmethod, referencecode, expiration) + e.db.createConsentRecord(userTOKEN, mode, address, brief, message, status, lawfulbasis, consentmethod, + referencecode, freetext, lastmodifiedby, starttime, expiration) } func (e mainEnv) consentCancel(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { diff --git a/src/consent_db.go b/src/consent_db.go index 60b4497..36b6ba2 100644 --- a/src/consent_db.go +++ b/src/consent_db.go @@ -11,22 +11,26 @@ import ( ) type consentEvent struct { - Endtime int32 `json:"endtime" structs:"endtime"` - When int32 `json:"when,omitempty" structs:"when"` - Who string `json:"who,omitempty" structs:"who"` - Mode string `json:"mode,omitempty" structs:"mode"` - Token string `json:"token" structs:"token"` - Brief string `json:"brief,omitempty" structs:"brief"` - Message string `json:"message,omitempty" structs:"message,omitempty"` - Status string `json:"status,omitempty" structs:"status"` - Lawfulbasis string `json:"lawfulbasis,omitempty" structs:"lawfulbasis"` - Consentmethod string `json:"consentmethod,omitempty" structs:"consentmethod"` - Referencecode string `json:"referencecode,omitempty" structs:"referencecode"` + Creationtime int32 `json:"creationtime" structs:"creationtime"` + Starttime int32 `json:"starttime" structs:"starttime"` + Endtime int32 `json:"endtime" structs:"endtime"` + When int32 `json:"when,omitempty" structs:"when"` + Who string `json:"who,omitempty" structs:"who"` + Mode string `json:"mode,omitempty" structs:"mode"` + Token string `json:"token" structs:"token"` + Brief string `json:"brief,omitempty" structs:"brief"` + Status string `json:"status,omitempty" structs:"status"` + Message string `json:"message,omitempty" structs:"message,omitempty"` + Freetext string `json:"freetext,omitempty" structs:"freetext,omitempty"` + Lawfulbasis string `json:"lawfulbasis,omitempty" structs:"lawfulbasis"` + Consentmethod string `json:"consentmethod,omitempty" structs:"consentmethod"` + Referencecode string `json:"referencecode,omitempty" structs:"referencecode,omitempty"` + Lastmodifiedby string `json:"lastmodifiedby,omitempty" structs:"lastmodifiedby,omitempty"` } func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode string, brief string, message string, status string, lawfulbasis string, consentmethod string, - referencecode string, endtime int32) { + referencecode string, freetext string, lastmodifiedby string, starttime int32, endtime int32) { now := int32(time.Now().Unix()) bdoc := bson.M{} bdoc["when"] = now @@ -42,6 +46,10 @@ func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode s if len(referencecode) > 0 { bdoc["referencecode"] = referencecode } + if len(freetext) > 0 { + bdoc["freetext"] = freetext + } + bdoc["lastmodifiedby"] = lastmodifiedby if len(userTOKEN) > 0 { // first check if this consent exists, then update raw, err := dbobj.getRecord2(TblName.Consent, "token", userTOKEN, "brief", brief) @@ -71,17 +79,20 @@ func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode s lawfulbasis = "consent" } ev := consentEvent{ - Endtime: endtime, - When: now, - Who: usercode, - Token: userTOKEN, - Mode: mode, - Brief: brief, - Message: message, - Status: status, - Lawfulbasis: lawfulbasis, - Consentmethod: consentmethod, - Referencecode: referencecode, + Creationtime: now, + Endtime: endtime, + When: now, + Who: usercode, + Token: userTOKEN, + Mode: mode, + Brief: brief, + Message: message, + Status: status, + Freetext: freetext, + Lawfulbasis: lawfulbasis, + Consentmethod: consentmethod, + Referencecode: referencecode, + Lastmodifiedby: lastmodifiedby, } // in any case - insert record _, err := dbobj.createRecord(TblName.Consent, structs.Map(ev)) diff --git a/src/qldb.go b/src/qldb.go index 5d7a70a..19e29b1 100644 --- a/src/qldb.go +++ b/src/qldb.go @@ -956,9 +956,13 @@ func initConsent(db *sql.DB) error { brief STRING, status STRING, message STRING, + freetext STRING, lawfulbasis STRING, consentmethod STRING, referencecode STRING, + lastmodifiedby STRING, + creationtime int, + starttime int, endtime int, ` + "`when` int);") if err != nil {