Add additional consent fields

This commit is contained in:
stremovsky
2019-12-25 14:25:12 +02:00
parent a578cae172
commit 0c658c512c
4 changed files with 72 additions and 31 deletions

12
API.md
View File

@@ -329,14 +329,14 @@ POST Body can contain regular form data or JSON. Here is a table with list of ex
| 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. |
| freetext (no) | Free text, used to internal usage. |
| message (no) | Text message describing consent. If empty **brief** is displayed. | | 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...| | 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...| | 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. | | 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**. | | lastmodifiedby (no) | Name of the person that last modified this record 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

@@ -64,17 +64,25 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro
//returnError(w, r, "internal error", 405, err, event) //returnError(w, r, "internal error", 405, err, event)
return return
} }
status := "accept"
message := "" message := ""
freetext := ""
lawfulbasis := "" lawfulbasis := ""
consentmethod := "" consentmethod := ""
referencecode := "" referencecode := ""
status := "accept" lastmodifiedby := ""
starttime := int32(0)
expiration := int32(0) expiration := int32(0)
if value, ok := records["message"]; ok { if value, ok := records["message"]; ok {
if reflect.TypeOf(value) == reflect.TypeOf("string") { if reflect.TypeOf(value) == reflect.TypeOf("string") {
message = value.(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 value, ok := records["lawfulbasis"]; ok {
if reflect.TypeOf(value) == reflect.TypeOf("string") { if reflect.TypeOf(value) == reflect.TypeOf("string") {
lawfulbasis = value.(string) lawfulbasis = value.(string)
@@ -90,6 +98,11 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro
referencecode = value.(string) 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 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)
@@ -107,13 +120,26 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro
expiration = value.(int32) 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 { switch mode {
case "email": case "email":
address = normalizeEmail(address) address = normalizeEmail(address)
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, 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) { func (e mainEnv) consentCancel(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

View File

@@ -11,22 +11,26 @@ import (
) )
type consentEvent struct { type consentEvent struct {
Endtime int32 `json:"endtime" structs:"endtime"` Creationtime int32 `json:"creationtime" structs:"creationtime"`
When int32 `json:"when,omitempty" structs:"when"` Starttime int32 `json:"starttime" structs:"starttime"`
Who string `json:"who,omitempty" structs:"who"` Endtime int32 `json:"endtime" structs:"endtime"`
Mode string `json:"mode,omitempty" structs:"mode"` When int32 `json:"when,omitempty" structs:"when"`
Token string `json:"token" structs:"token"` Who string `json:"who,omitempty" structs:"who"`
Brief string `json:"brief,omitempty" structs:"brief"` Mode string `json:"mode,omitempty" structs:"mode"`
Message string `json:"message,omitempty" structs:"message,omitempty"` Token string `json:"token" structs:"token"`
Status string `json:"status,omitempty" structs:"status"` Brief string `json:"brief,omitempty" structs:"brief"`
Lawfulbasis string `json:"lawfulbasis,omitempty" structs:"lawfulbasis"` Status string `json:"status,omitempty" structs:"status"`
Consentmethod string `json:"consentmethod,omitempty" structs:"consentmethod"` Message string `json:"message,omitempty" structs:"message,omitempty"`
Referencecode string `json:"referencecode,omitempty" structs:"referencecode"` 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, func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode string,
brief string, message string, status string, lawfulbasis string, consentmethod 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()) now := int32(time.Now().Unix())
bdoc := bson.M{} bdoc := bson.M{}
bdoc["when"] = now bdoc["when"] = now
@@ -42,6 +46,10 @@ func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode s
if len(referencecode) > 0 { if len(referencecode) > 0 {
bdoc["referencecode"] = referencecode bdoc["referencecode"] = referencecode
} }
if len(freetext) > 0 {
bdoc["freetext"] = freetext
}
bdoc["lastmodifiedby"] = lastmodifiedby
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)
@@ -71,17 +79,20 @@ func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode s
lawfulbasis = "consent" lawfulbasis = "consent"
} }
ev := consentEvent{ ev := consentEvent{
Endtime: endtime, Creationtime: now,
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,
Lawfulbasis: lawfulbasis, Status: status,
Consentmethod: consentmethod, Freetext: freetext,
Referencecode: referencecode, Lawfulbasis: lawfulbasis,
Consentmethod: consentmethod,
Referencecode: referencecode,
Lastmodifiedby: lastmodifiedby,
} }
// 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

@@ -956,9 +956,13 @@ func initConsent(db *sql.DB) error {
brief STRING, brief STRING,
status STRING, status STRING,
message STRING, message STRING,
freetext STRING,
lawfulbasis STRING, lawfulbasis STRING,
consentmethod STRING, consentmethod STRING,
referencecode STRING, referencecode STRING,
lastmodifiedby STRING,
creationtime int,
starttime int,
endtime int, endtime int,
` + "`when` int);") ` + "`when` int);")
if err != nil { if err != nil {