From 8a5efd86c833f8ae2e1dc0b5fd7b3dbd35db6c6d Mon Sep 17 00:00:00 2001 From: stremovsky Date: Sat, 4 Jan 2020 21:05:24 +0200 Subject: [PATCH] change consent values --- src/bunker.go | 8 ++++++-- src/consent_api.go | 12 ++++++------ src/consent_db.go | 6 +++--- src/utils.go | 17 +++++++++++++---- ui/site/style.css | 3 +++ ui/site/user-data-processing.html | 6 +++--- 6 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/bunker.go b/src/bunker.go index fc86a42..811c2ff 100644 --- a/src/bunker.go +++ b/src/bunker.go @@ -169,7 +169,7 @@ func (e mainEnv) setupRouter() *httprouter.Router { router.GET("/v1/consent/:mode/:address/:brief", e.consentUserRecord) router.GET("/v1/consents/:brief", e.consentFilterRecords) router.POST("/v1/consent/:mode/:address/:brief", e.consentAccept) - router.DELETE("/v1/consent/:mode/:address/:brief", e.consentCancel) + router.DELETE("/v1/consent/:mode/:address/:brief", e.consentWithdraw) router.POST("/v1/userapp/token/:token/:appname", e.userappNew) router.GET("/v1/userapp/token/:token/:appname", e.userappGet) @@ -197,7 +197,11 @@ func (e mainEnv) setupRouter() *httprouter.Router { } }) router.GET("/site/*filepath", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { - data, err := box.Find(r.URL.Path) + fname := r.URL.Path + if fname == "/site/" { + fname = "/site/index.html" + } + data, err := box.Find(fname) if err != nil { w.WriteHeader(404) } else { diff --git a/src/consent_api.go b/src/consent_api.go index a2ed6e0..649ecf7 100644 --- a/src/consent_api.go +++ b/src/consent_api.go @@ -64,7 +64,7 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro //returnError(w, r, "internal error", 405, err, event) return } - status := "accept" + status := "yes" message := "" freetext := "" lawfulbasis := "" @@ -105,7 +105,7 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro } if value, ok := records["status"]; ok { if reflect.TypeOf(value) == reflect.TypeOf("string") { - status = value.(string) + status = normalizeConsentStatus(value.(string)) } } if value, ok := records["expiration"]; ok { @@ -151,7 +151,7 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro } } -func (e mainEnv) consentCancel(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { +func (e mainEnv) consentWithdraw(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { address := ps.ByName("address") brief := ps.ByName("brief") mode := ps.ByName("mode") @@ -218,15 +218,15 @@ 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, lastmodifiedby) + e.db.withdrawConsentRecord(userTOKEN, brief, mode, address, lastmodifiedby) w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) w.Write([]byte(`{"status":"ok"}`)) notifyUrl := e.conf.Notification.Consent_notification_url if len(userTOKEN) > 0 { - notifyConsentChange(notifyUrl, brief, "cancel", "token", userTOKEN) + notifyConsentChange(notifyUrl, brief, "no", "token", userTOKEN) } else { - notifyConsentChange(notifyUrl, brief, "cancel", mode, address) + notifyConsentChange(notifyUrl, brief, "no", mode, address) } } diff --git a/src/consent_db.go b/src/consent_db.go index 62cc3c9..6a5e738 100644 --- a/src/consent_db.go +++ b/src/consent_db.go @@ -119,7 +119,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, lastmodifiedby string) error { +func (dbobj dbcon) withdrawConsentRecord(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") @@ -131,7 +131,7 @@ func (dbobj dbcon) cancelConsentRecord(userTOKEN string, brief string, mode stri bdoc["mode"] = mode bdoc["who"] = usercode bdoc["endtime"] = 0 - bdoc["status"] = "cancel" + bdoc["status"] = "no" bdoc["lastmodifiedby"] = lastmodifiedby if len(userTOKEN) > 0 { fmt.Printf("%s %s\n", userTOKEN, brief) @@ -186,7 +186,7 @@ func (dbobj dbcon) filterConsentRecords(brief string, offset int32, limit int32) } func (dbobj dbcon) expireConsentRecords(notifyUrl string) error { - records, err := dbobj.getExpiring(TblName.Consent, "status", "accept") + records, err := dbobj.getExpiring(TblName.Consent, "status", "yes") if err != nil { return err } diff --git a/src/utils.go b/src/utils.go index 56e5215..afdacd9 100644 --- a/src/utils.go +++ b/src/utils.go @@ -23,10 +23,11 @@ import ( ) var ( - regexUUID = regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$") - regexBrief = regexp.MustCompile("^[a-z0-9\\-]{1,64}$") - regexAppName = regexp.MustCompile("^[a-z][a-z0-9]{1,20}$") - regexExpiration = regexp.MustCompile("^([0-9]+)([mhds])?$") + regexUUID = regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$") + regexBrief = regexp.MustCompile("^[a-z0-9\\-]{1,64}$") + regexAppName = regexp.MustCompile("^[a-z][a-z0-9]{1,20}$") + regexExpiration = regexp.MustCompile("^([0-9]+)([mhds])?$") + consentYesStatuses = []string{"yes", "accept", "given", "true", "agree"} ) // Consideration why collection of meta data patch was postpone: @@ -59,6 +60,14 @@ func hashString(hash []byte, src string) string { return base64.StdEncoding.EncodeToString(hashed[:]) } +func normalizeConsentStatus(status string) string { + status = strings.ToLower(status) + if contains(consentYesStatuses, status) { + return "yes" + } + return "no" +} + func normalizeBrief(brief string) string { return strings.ToLower(brief) } diff --git a/ui/site/style.css b/ui/site/style.css index 384a6e8..b6784a1 100644 --- a/ui/site/style.css +++ b/ui/site/style.css @@ -117,4 +117,7 @@ h4 { white-space: nowrap; overflow: hidden; max-width: 130px; +} +.bigblock .jsoneditor { + border: none; } \ No newline at end of file diff --git a/ui/site/user-data-processing.html b/ui/site/user-data-processing.html index d084528..bf2e65b 100644 --- a/ui/site/user-data-processing.html +++ b/ui/site/user-data-processing.html @@ -171,10 +171,10 @@ info = info + 'Additional info: ' + row.freetext + '
'; } info = info + '' - var cancel = "Withdraw"; + var withdraw = "Withdraw"; var accept = "Give"; - var op = cancel; - if (row.status != 'accept') { + var op = withdraw; + if (row.status != 'yes') { op = accept; } var status = '
Consent Given: ' + row.status + '
' + op + '
'