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 |
| --------------------- | ------------------------------------------------------------------------------ |
| 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**.

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)
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) {

View File

@@ -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))

View File

@@ -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 {