save lastmodifiedby field

This commit is contained in:
stremovsky
2019-12-25 15:10:40 +02:00
parent 0c658c512c
commit 9b6b9d3bc9
3 changed files with 16 additions and 4 deletions

4
API.md
View File

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

View File

@@ -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"}`))

View File

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