mirror of
				https://github.com/optim-enterprises-bv/databunker.git
				synced 2025-10-31 01:47:57 +00:00 
			
		
		
		
	adding lawfulbasis, consentmethod, referencecode fields to consent records
This commit is contained in:
		
							
								
								
									
										16
									
								
								API.md
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								API.md
									
									
									
									
									
								
							| @@ -326,11 +326,17 @@ This API is used to store user consent. | |||||||
|  |  | ||||||
| POST Body can contain regular form data or JSON. Here is a table with list of expected parameters. | POST Body can contain regular form data or JSON. Here is a table with list of expected parameters. | ||||||
|  |  | ||||||
| | Parameter   | Required  | Description                                                                    | | | Parameter (required)  | Description                                                                    | | ||||||
| | ----------- | --------- | ------------------------------------------------------------------------------ | | | --------------------- | ------------------------------------------------------------------------------ | | ||||||
| | status      | No        | Consent status. Default value is **accept**. Allowed values: cancel/accept.    | | | status (no)           | Consent status. Default value is **accept**. Allowed values: cancel/accept.    | | ||||||
| | message     | No        | Optional text message describing consent.                                      | | | freetext (no)         | Free text, used to internal usage.                                             | | ||||||
| | expiration  | No        | Optional consent expiration date. It is an integer number in UNIX time format. | | | 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.      | | ||||||
|  | | 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.                                                 | | ||||||
|  |  | ||||||
| When consent is expired, the status value is changed to **expired**. | When consent is expired, the status value is changed to **expired**. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -65,6 +65,9 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	message := "" | 	message := "" | ||||||
|  | 	lawfulbasis := "" | ||||||
|  | 	consentmethod := "" | ||||||
|  | 	referencecode := "" | ||||||
| 	status := "accept" | 	status := "accept" | ||||||
| 	expiration := int32(0) | 	expiration := int32(0) | ||||||
| 	if value, ok := records["message"]; ok { | 	if value, ok := records["message"]; ok { | ||||||
| @@ -72,6 +75,21 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro | |||||||
| 			message = value.(string) | 			message = value.(string) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	if value, ok := records["lawfulbasis"]; ok { | ||||||
|  | 		if reflect.TypeOf(value) == reflect.TypeOf("string") { | ||||||
|  | 			lawfulbasis = value.(string) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	if value, ok := records["consentmethod"]; ok { | ||||||
|  | 		if reflect.TypeOf(value) == reflect.TypeOf("string") { | ||||||
|  | 			consentmethod = value.(string) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	if value, ok := records["referencecode"]; ok { | ||||||
|  | 		if reflect.TypeOf(value) == reflect.TypeOf("string") { | ||||||
|  | 			referencecode = value.(string) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 	if value, ok := records["status"]; ok { | 	if value, ok := records["status"]; ok { | ||||||
| 		if reflect.TypeOf(value) == reflect.TypeOf("string") { | 		if reflect.TypeOf(value) == reflect.TypeOf("string") { | ||||||
| 			status = value.(string) | 			status = value.(string) | ||||||
| @@ -95,7 +113,7 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro | |||||||
| 	case "phone": | 	case "phone": | ||||||
| 		address = normalizePhone(address, e.conf.Sms.Default_country) | 		address = normalizePhone(address, e.conf.Sms.Default_country) | ||||||
| 	} | 	} | ||||||
| 	e.db.createConsentRecord(userTOKEN, mode, address, brief, message, status, expiration) | 	e.db.createConsentRecord(userTOKEN, mode, address, brief, message, status, lawfulbasis, consentmethod, referencecode, expiration) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (e mainEnv) consentCancel(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | func (e mainEnv) consentCancel(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | ||||||
|   | |||||||
| @@ -11,6 +11,7 @@ import ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| type consentEvent struct { | type consentEvent struct { | ||||||
|  | 	Endtime       int32  `json:"endtime" structs:"endtime"` | ||||||
| 	When          int32  `json:"when,omitempty" structs:"when"` | 	When          int32  `json:"when,omitempty" structs:"when"` | ||||||
| 	Who           string `json:"who,omitempty" structs:"who"` | 	Who           string `json:"who,omitempty" structs:"who"` | ||||||
| 	Mode          string `json:"mode,omitempty" structs:"mode"` | 	Mode          string `json:"mode,omitempty" structs:"mode"` | ||||||
| @@ -18,11 +19,29 @@ type consentEvent struct { | |||||||
| 	Brief         string `json:"brief,omitempty" structs:"brief"` | 	Brief         string `json:"brief,omitempty" structs:"brief"` | ||||||
| 	Message       string `json:"message,omitempty" structs:"message,omitempty"` | 	Message       string `json:"message,omitempty" structs:"message,omitempty"` | ||||||
| 	Status        string `json:"status,omitempty" structs:"status"` | 	Status        string `json:"status,omitempty" structs:"status"` | ||||||
| 	Endtime int32  `json:"endtime" structs:"endtime"` | 	Lawfulbasis   string `json:"lawfulbasis,omitempty" structs:"lawfulbasis"` | ||||||
|  | 	Consentmethod string `json:"consentmethod,omitempty" structs:"consentmethod"` | ||||||
|  | 	Referencecode string `json:"referencecode,omitempty" structs:"referencecode"` | ||||||
| } | } | ||||||
|  |  | ||||||
| func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode string, brief string, message string, status string, endtime int32) { | func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode string, | ||||||
|  | 	brief string, message string, status string, lawfulbasis string, consentmethod string, | ||||||
|  | 	referencecode string, endtime int32) { | ||||||
| 	now := int32(time.Now().Unix()) | 	now := int32(time.Now().Unix()) | ||||||
|  | 	bdoc := bson.M{} | ||||||
|  | 	bdoc["when"] = now | ||||||
|  | 	bdoc["status"] = status | ||||||
|  | 	bdoc["endtime"] = endtime | ||||||
|  | 	if len(lawfulbasis) > 0 { | ||||||
|  | 		// in case of update, consent, use new value | ||||||
|  | 		bdoc["lawfulbasis"] = lawfulbasis | ||||||
|  | 	} | ||||||
|  | 	if len(consentmethod) > 0 { | ||||||
|  | 		bdoc["consentmethod"] = consentmethod | ||||||
|  | 	} | ||||||
|  | 	if len(referencecode) > 0 { | ||||||
|  | 		bdoc["referencecode"] = referencecode | ||||||
|  | 	} | ||||||
| 	if len(userTOKEN) > 0 { | 	if len(userTOKEN) > 0 { | ||||||
| 		// first check if this consent exists, then update | 		// first check if this consent exists, then update | ||||||
| 		raw, err := dbobj.getRecord2(TblName.Consent, "token", userTOKEN, "brief", brief) | 		raw, err := dbobj.getRecord2(TblName.Consent, "token", userTOKEN, "brief", brief) | ||||||
| @@ -31,11 +50,6 @@ func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode s | |||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| 		if raw != nil { | 		if raw != nil { | ||||||
| 			// update date, status |  | ||||||
| 			bdoc := bson.M{} |  | ||||||
| 			bdoc["when"] = now |  | ||||||
| 			bdoc["status"] = status |  | ||||||
| 			bdoc["endtime"] = endtime |  | ||||||
| 			dbobj.updateRecord2(TblName.Consent, "token", userTOKEN, "brief", brief, &bdoc, nil) | 			dbobj.updateRecord2(TblName.Consent, "token", userTOKEN, "brief", brief, &bdoc, nil) | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| @@ -46,17 +60,18 @@ func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode s | |||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| 		if raw != nil { | 		if raw != nil { | ||||||
| 			fmt.Println("update rec") |  | ||||||
| 			// update date, status |  | ||||||
| 			bdoc := bson.M{} |  | ||||||
| 			bdoc["when"] = now |  | ||||||
| 			bdoc["status"] = status |  | ||||||
| 			bdoc["endtime"] = endtime |  | ||||||
| 			dbobj.updateRecord2(TblName.Consent, "who", usercode, "brief", brief, &bdoc, nil) | 			dbobj.updateRecord2(TblName.Consent, "who", usercode, "brief", brief, &bdoc, nil) | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	if len(consentmethod) == 0 { | ||||||
|  | 		consentmethod = "api" | ||||||
|  | 	} | ||||||
|  | 	if len(lawfulbasis) == 0 { | ||||||
|  | 		lawfulbasis = "consent" | ||||||
|  | 	} | ||||||
| 	ev := consentEvent{ | 	ev := consentEvent{ | ||||||
|  | 		Endtime:       endtime, | ||||||
| 		When:          now, | 		When:          now, | ||||||
| 		Who:           usercode, | 		Who:           usercode, | ||||||
| 		Token:         userTOKEN, | 		Token:         userTOKEN, | ||||||
| @@ -64,7 +79,9 @@ func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode s | |||||||
| 		Brief:         brief, | 		Brief:         brief, | ||||||
| 		Message:       message, | 		Message:       message, | ||||||
| 		Status:        status, | 		Status:        status, | ||||||
| 		Endtime: endtime, | 		Lawfulbasis:   lawfulbasis, | ||||||
|  | 		Consentmethod: consentmethod, | ||||||
|  | 		Referencecode: referencecode, | ||||||
| 	} | 	} | ||||||
| 	// in any case - insert record | 	// in any case - insert record | ||||||
| 	_, err := dbobj.createRecord(TblName.Consent, structs.Map(ev)) | 	_, err := dbobj.createRecord(TblName.Consent, structs.Map(ev)) | ||||||
|   | |||||||
| @@ -954,8 +954,11 @@ func initConsent(db *sql.DB) error { | |||||||
| 	  mode STRING, | 	  mode STRING, | ||||||
| 	  token STRING, | 	  token STRING, | ||||||
| 	  brief STRING, | 	  brief STRING, | ||||||
| 	  message STRING, |  | ||||||
| 	  status STRING, | 	  status STRING, | ||||||
|  | 	  message STRING, | ||||||
|  | 	  lawfulbasis STRING, | ||||||
|  | 	  consentmethod STRING, | ||||||
|  | 	  referencecode STRING, | ||||||
| 	  endtime int, | 	  endtime int, | ||||||
| 	  ` + "`when` int);") | 	  ` + "`when` int);") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 stremovsky
					stremovsky