From 9b6b9d3bc96e07ef28ce6f93f82cff9b6b603131 Mon Sep 17 00:00:00 2001 From: stremovsky Date: Wed, 25 Dec 2019 15:10:40 +0200 Subject: [PATCH] save lastmodifiedby field --- API.md | 4 ++-- src/consent_api.go | 13 ++++++++++++- src/consent_db.go | 3 ++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/API.md b/API.md index 7226e5c..d728e40 100644 --- a/API.md +++ b/API.md @@ -331,8 +331,8 @@ POST Body can contain regular form data or JSON. Here is a table with list of ex | status (no) | Consent status. Default value is **accept**. Allowed values: cancel/accept. | | message (no) | Text message describing consent. If empty **brief** is displayed. | | 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...| +| starttime (no) | Date & time to automatically enable this consent. Expected value is in UNIX time format or kind of 10d or 1m, etc...| +| expiration (no) | Consent expiration date. Expected value 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**, **web-consent**, **email-consent**, etc...| | referencecode (no) | This can be used as an id of your internal document, contract, etc... | diff --git a/src/consent_api.go b/src/consent_api.go index 157ce8e..e8d2d9b 100644 --- a/src/consent_api.go +++ b/src/consent_api.go @@ -188,6 +188,17 @@ func (e mainEnv) consentCancel(w http.ResponseWriter, r *http.Request, ps httpro // else user not found - we allow to save consent for unlinked users! } } + records, err := getJSONPostData(r) + if err != nil { + //returnError(w, r, "internal error", 405, err, event) + return + } + lastmodifiedby := "" + if value, ok := records["lastmodifiedby"]; ok { + if reflect.TypeOf(value) == reflect.TypeOf("string") { + lastmodifiedby = value.(string) + } + } // make sure that user is logged in here, unless he wants to cancel emails //if e.enforceAuth(w, r, event) == false { // return @@ -198,7 +209,7 @@ func (e mainEnv) consentCancel(w http.ResponseWriter, r *http.Request, ps httpro case "phone": address = normalizePhone(address, e.conf.Sms.Default_country) } - e.db.cancelConsentRecord(userTOKEN, brief, mode, address) + e.db.cancelConsentRecord(userTOKEN, brief, mode, address, lastmodifiedby) w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) w.Write([]byte(`{"status":"ok"}`)) diff --git a/src/consent_db.go b/src/consent_db.go index 36b6ba2..b98e06b 100644 --- a/src/consent_db.go +++ b/src/consent_db.go @@ -109,7 +109,7 @@ func (dbobj dbcon) linkConsentRecords(userTOKEN string, mode string, usercode st return err } -func (dbobj dbcon) cancelConsentRecord(userTOKEN string, brief string, mode string, usercode string) error { +func (dbobj dbcon) cancelConsentRecord(userTOKEN string, brief string, mode string, usercode string, lastmodifiedby string) error { // brief can not be too long, may be hash it ? if len(brief) > 64 { return errors.New("Brief value is too long") @@ -122,6 +122,7 @@ func (dbobj dbcon) cancelConsentRecord(userTOKEN string, brief string, mode stri bdoc["who"] = usercode bdoc["endtime"] = 0 bdoc["status"] = "cancel" + bdoc["lastmodifiedby"] = lastmodifiedby if len(userTOKEN) > 0 { fmt.Printf("%s %s\n", userTOKEN, brief) dbobj.updateRecord2(TblName.Consent, "token", userTOKEN, "brief", brief, &bdoc, nil)