mirror of
https://github.com/outbackdingo/databunker.git
synced 2026-01-27 18:18:43 +00:00
change consent values
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
17
src/utils.go
17
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)
|
||||
}
|
||||
|
||||
@@ -117,4 +117,7 @@ h4 {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
max-width: 130px;
|
||||
}
|
||||
.bigblock .jsoneditor {
|
||||
border: none;
|
||||
}
|
||||
@@ -171,10 +171,10 @@
|
||||
info = info + '<small>Additional info: ' + row.freetext + '</small><br/>';
|
||||
}
|
||||
info = info + '</div>'
|
||||
var cancel = "<a href=\"javascript:confirmWithdrawal('" + row.brief + "');\">Withdraw</a>";
|
||||
var withdraw = "<a href=\"javascript:confirmWithdrawal('" + row.brief + "');\">Withdraw</a>";
|
||||
var accept = "<a href=\"javascript:acceptConsent('" + row.brief + "');\">Give</a>";
|
||||
var op = cancel;
|
||||
if (row.status != 'accept') {
|
||||
var op = withdraw;
|
||||
if (row.status != 'yes') {
|
||||
op = accept;
|
||||
}
|
||||
var status = '<div class="col-3"><center>Consent Given: ' + row.status + '</br>' + op + '</center></div>'
|
||||
|
||||
Reference in New Issue
Block a user