adding lawfulbasis, consentmethod, referencecode fields to consent records

This commit is contained in:
stremovsky
2019-12-25 12:08:53 +02:00
parent bdd1c28394
commit a3640586fa
4 changed files with 79 additions and 35 deletions

16
API.md
View File

@@ -326,11 +326,17 @@ This API is used to store user consent.
POST Body can contain regular form data or JSON. Here is a table with list of expected parameters. POST Body can contain regular form data or JSON. Here is a table with list of expected parameters.
| Parameter | Required | Description | | Parameter (required) | Description |
| ----------- | --------- | ------------------------------------------------------------------------------ | | --------------------- | ------------------------------------------------------------------------------ |
| status | No | Consent status. Default value is **accept**. Allowed values: cancel/accept. | | status (no) | Consent status. Default value is **accept**. Allowed values: cancel/accept. |
| message | No | Optional text message describing consent. | | freetext (no) | Free text, used to internal usage. |
| expiration | No | Optional consent expiration date. It is an integer number in UNIX time format. | | 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. |
| 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. |
When consent is expired, the status value is changed to **expired**. When consent is expired, the status value is changed to **expired**.

View File

@@ -65,6 +65,9 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro
return return
} }
message := "" message := ""
lawfulbasis := ""
consentmethod := ""
referencecode := ""
status := "accept" status := "accept"
expiration := int32(0) expiration := int32(0)
if value, ok := records["message"]; ok { if value, ok := records["message"]; ok {
@@ -72,6 +75,21 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro
message = value.(string) message = value.(string)
} }
} }
if value, ok := records["lawfulbasis"]; ok {
if reflect.TypeOf(value) == reflect.TypeOf("string") {
lawfulbasis = value.(string)
}
}
if value, ok := records["consentmethod"]; ok {
if reflect.TypeOf(value) == reflect.TypeOf("string") {
consentmethod = value.(string)
}
}
if value, ok := records["referencecode"]; ok {
if reflect.TypeOf(value) == reflect.TypeOf("string") {
referencecode = value.(string)
}
}
if value, ok := records["status"]; ok { if value, ok := records["status"]; ok {
if reflect.TypeOf(value) == reflect.TypeOf("string") { if reflect.TypeOf(value) == reflect.TypeOf("string") {
status = value.(string) status = value.(string)
@@ -95,7 +113,7 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro
case "phone": case "phone":
address = normalizePhone(address, e.conf.Sms.Default_country) address = normalizePhone(address, e.conf.Sms.Default_country)
} }
e.db.createConsentRecord(userTOKEN, mode, address, brief, message, status, expiration) e.db.createConsentRecord(userTOKEN, mode, address, brief, message, status, lawfulbasis, consentmethod, referencecode, expiration)
} }
func (e mainEnv) consentCancel(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { func (e mainEnv) consentCancel(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

View File

@@ -11,18 +11,37 @@ import (
) )
type consentEvent struct { type consentEvent struct {
When int32 `json:"when,omitempty" structs:"when"` Endtime int32 `json:"endtime" structs:"endtime"`
Who string `json:"who,omitempty" structs:"who"` When int32 `json:"when,omitempty" structs:"when"`
Mode string `json:"mode,omitempty" structs:"mode"` Who string `json:"who,omitempty" structs:"who"`
Token string `json:"token" structs:"token"` Mode string `json:"mode,omitempty" structs:"mode"`
Brief string `json:"brief,omitempty" structs:"brief"` Token string `json:"token" structs:"token"`
Message string `json:"message,omitempty" structs:"message,omitempty"` Brief string `json:"brief,omitempty" structs:"brief"`
Status string `json:"status,omitempty" structs:"status"` Message string `json:"message,omitempty" structs:"message,omitempty"`
Endtime int32 `json:"endtime" structs:"endtime"` 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"`
} }
func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode string, brief string, message string, status string, endtime int32) { func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode string,
brief string, message string, status string, lawfulbasis string, consentmethod string,
referencecode string, endtime int32) {
now := int32(time.Now().Unix()) now := int32(time.Now().Unix())
bdoc := bson.M{}
bdoc["when"] = now
bdoc["status"] = status
bdoc["endtime"] = endtime
if len(lawfulbasis) > 0 {
// in case of update, consent, use new value
bdoc["lawfulbasis"] = lawfulbasis
}
if len(consentmethod) > 0 {
bdoc["consentmethod"] = consentmethod
}
if len(referencecode) > 0 {
bdoc["referencecode"] = referencecode
}
if len(userTOKEN) > 0 { if len(userTOKEN) > 0 {
// first check if this consent exists, then update // first check if this consent exists, then update
raw, err := dbobj.getRecord2(TblName.Consent, "token", userTOKEN, "brief", brief) raw, err := dbobj.getRecord2(TblName.Consent, "token", userTOKEN, "brief", brief)
@@ -31,11 +50,6 @@ func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode s
return return
} }
if raw != nil { if raw != nil {
// update date, status
bdoc := bson.M{}
bdoc["when"] = now
bdoc["status"] = status
bdoc["endtime"] = endtime
dbobj.updateRecord2(TblName.Consent, "token", userTOKEN, "brief", brief, &bdoc, nil) dbobj.updateRecord2(TblName.Consent, "token", userTOKEN, "brief", brief, &bdoc, nil)
return return
} }
@@ -46,25 +60,28 @@ func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode s
return return
} }
if raw != nil { if raw != nil {
fmt.Println("update rec")
// update date, status
bdoc := bson.M{}
bdoc["when"] = now
bdoc["status"] = status
bdoc["endtime"] = endtime
dbobj.updateRecord2(TblName.Consent, "who", usercode, "brief", brief, &bdoc, nil) dbobj.updateRecord2(TblName.Consent, "who", usercode, "brief", brief, &bdoc, nil)
return return
} }
} }
if len(consentmethod) == 0 {
consentmethod = "api"
}
if len(lawfulbasis) == 0 {
lawfulbasis = "consent"
}
ev := consentEvent{ ev := consentEvent{
When: now, Endtime: endtime,
Who: usercode, When: now,
Token: userTOKEN, Who: usercode,
Mode: mode, Token: userTOKEN,
Brief: brief, Mode: mode,
Message: message, Brief: brief,
Status: status, Message: message,
Endtime: endtime, Status: status,
Lawfulbasis: lawfulbasis,
Consentmethod: consentmethod,
Referencecode: referencecode,
} }
// in any case - insert record // in any case - insert record
_, err := dbobj.createRecord(TblName.Consent, structs.Map(ev)) _, err := dbobj.createRecord(TblName.Consent, structs.Map(ev))

View File

@@ -954,8 +954,11 @@ func initConsent(db *sql.DB) error {
mode STRING, mode STRING,
token STRING, token STRING,
brief STRING, brief STRING,
message STRING,
status STRING, status STRING,
message STRING,
lawfulbasis STRING,
consentmethod STRING,
referencecode STRING,
endtime int, endtime int,
` + "`when` int);") ` + "`when` int);")
if err != nil { if err != nil {