mirror of
				https://github.com/optim-enterprises-bv/databunker.git
				synced 2025-10-31 01:47:57 +00:00 
			
		
		
		
	Add additional consent fields
This commit is contained in:
		
							
								
								
									
										12
									
								
								API.md
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								API.md
									
									
									
									
									
								
							| @@ -329,14 +329,14 @@ POST Body can contain regular form data or JSON. Here is a table with list of ex | |||||||
| | 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.    | | ||||||
| | freetext (no)         | Free text, used to internal usage.                                             | |  | ||||||
| | message (no)          | Text message describing consent. If empty **brief** is displayed.              | | | 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.      | | | 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...| | ||||||
| | lawfulbasis (no)      | Default is **consent**. It can be: **contract-agreement**, **legal-obligations**, 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**, 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.            | | | 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**.            | | | lastmodifiedby (no)   | Name of the person that last modified this record 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**. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -64,17 +64,25 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro | |||||||
| 		//returnError(w, r, "internal error", 405, err, event) | 		//returnError(w, r, "internal error", 405, err, event) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  | 	status := "accept" | ||||||
| 	message := "" | 	message := "" | ||||||
|  | 	freetext := "" | ||||||
| 	lawfulbasis := "" | 	lawfulbasis := "" | ||||||
| 	consentmethod := "" | 	consentmethod := "" | ||||||
| 	referencecode := "" | 	referencecode := "" | ||||||
| 	status := "accept" | 	lastmodifiedby := "" | ||||||
|  | 	starttime := int32(0) | ||||||
| 	expiration := int32(0) | 	expiration := int32(0) | ||||||
| 	if value, ok := records["message"]; ok { | 	if value, ok := records["message"]; ok { | ||||||
| 		if reflect.TypeOf(value) == reflect.TypeOf("string") { | 		if reflect.TypeOf(value) == reflect.TypeOf("string") { | ||||||
| 			message = value.(string) | 			message = value.(string) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	if value, ok := records["freetext"]; ok { | ||||||
|  | 		if reflect.TypeOf(value) == reflect.TypeOf("string") { | ||||||
|  | 			freetext = value.(string) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 	if value, ok := records["lawfulbasis"]; ok { | 	if value, ok := records["lawfulbasis"]; ok { | ||||||
| 		if reflect.TypeOf(value) == reflect.TypeOf("string") { | 		if reflect.TypeOf(value) == reflect.TypeOf("string") { | ||||||
| 			lawfulbasis = value.(string) | 			lawfulbasis = value.(string) | ||||||
| @@ -90,6 +98,11 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro | |||||||
| 			referencecode = value.(string) | 			referencecode = value.(string) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	if value, ok := records["lastmodifiedby"]; ok { | ||||||
|  | 		if reflect.TypeOf(value) == reflect.TypeOf("string") { | ||||||
|  | 			lastmodifiedby = 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) | ||||||
| @@ -107,13 +120,26 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro | |||||||
| 			expiration = value.(int32) | 			expiration = value.(int32) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	if value, ok := records["starttime"]; ok { | ||||||
|  | 		switch records["starttime"].(type) { | ||||||
|  | 		case string: | ||||||
|  | 			starttime, _ = parseExpiration(value.(string)) | ||||||
|  | 		case int: | ||||||
|  | 			starttime = value.(int32) | ||||||
|  | 		case int32: | ||||||
|  | 			starttime = value.(int32) | ||||||
|  | 		case int64: | ||||||
|  | 			starttime = value.(int32) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 	switch mode { | 	switch mode { | ||||||
| 	case "email": | 	case "email": | ||||||
| 		address = normalizeEmail(address) | 		address = normalizeEmail(address) | ||||||
| 	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, lawfulbasis, consentmethod, referencecode, expiration) | 	e.db.createConsentRecord(userTOKEN, mode, address, brief, message, status, lawfulbasis, consentmethod, | ||||||
|  | 		referencecode, freetext, lastmodifiedby, starttime, 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,22 +11,26 @@ import ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| type consentEvent struct { | type consentEvent struct { | ||||||
|  | 	Creationtime   int32  `json:"creationtime" structs:"creationtime"` | ||||||
|  | 	Starttime      int32  `json:"starttime" structs:"starttime"` | ||||||
| 	Endtime        int32  `json:"endtime" structs:"endtime"` | 	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"` | ||||||
| 	Token          string `json:"token" structs:"token"` | 	Token          string `json:"token" structs:"token"` | ||||||
| 	Brief          string `json:"brief,omitempty" structs:"brief"` | 	Brief          string `json:"brief,omitempty" structs:"brief"` | ||||||
| 	Message       string `json:"message,omitempty" structs:"message,omitempty"` |  | ||||||
| 	Status         string `json:"status,omitempty" structs:"status"` | 	Status         string `json:"status,omitempty" structs:"status"` | ||||||
|  | 	Message        string `json:"message,omitempty" structs:"message,omitempty"` | ||||||
|  | 	Freetext       string `json:"freetext,omitempty" structs:"freetext,omitempty"` | ||||||
| 	Lawfulbasis    string `json:"lawfulbasis,omitempty" structs:"lawfulbasis"` | 	Lawfulbasis    string `json:"lawfulbasis,omitempty" structs:"lawfulbasis"` | ||||||
| 	Consentmethod  string `json:"consentmethod,omitempty" structs:"consentmethod"` | 	Consentmethod  string `json:"consentmethod,omitempty" structs:"consentmethod"` | ||||||
| 	Referencecode string `json:"referencecode,omitempty" structs:"referencecode"` | 	Referencecode  string `json:"referencecode,omitempty" structs:"referencecode,omitempty"` | ||||||
|  | 	Lastmodifiedby string `json:"lastmodifiedby,omitempty" structs:"lastmodifiedby,omitempty"` | ||||||
| } | } | ||||||
|  |  | ||||||
| func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode string, | func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode string, | ||||||
| 	brief string, message string, status string, lawfulbasis string, consentmethod string, | 	brief string, message string, status string, lawfulbasis string, consentmethod string, | ||||||
| 	referencecode string, endtime int32) { | 	referencecode string, freetext string, lastmodifiedby string, starttime int32, endtime int32) { | ||||||
| 	now := int32(time.Now().Unix()) | 	now := int32(time.Now().Unix()) | ||||||
| 	bdoc := bson.M{} | 	bdoc := bson.M{} | ||||||
| 	bdoc["when"] = now | 	bdoc["when"] = now | ||||||
| @@ -42,6 +46,10 @@ func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode s | |||||||
| 	if len(referencecode) > 0 { | 	if len(referencecode) > 0 { | ||||||
| 		bdoc["referencecode"] = referencecode | 		bdoc["referencecode"] = referencecode | ||||||
| 	} | 	} | ||||||
|  | 	if len(freetext) > 0 { | ||||||
|  | 		bdoc["freetext"] = freetext | ||||||
|  | 	} | ||||||
|  | 	bdoc["lastmodifiedby"] = lastmodifiedby | ||||||
| 	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) | ||||||
| @@ -71,6 +79,7 @@ func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode s | |||||||
| 		lawfulbasis = "consent" | 		lawfulbasis = "consent" | ||||||
| 	} | 	} | ||||||
| 	ev := consentEvent{ | 	ev := consentEvent{ | ||||||
|  | 		Creationtime:   now, | ||||||
| 		Endtime:        endtime, | 		Endtime:        endtime, | ||||||
| 		When:           now, | 		When:           now, | ||||||
| 		Who:            usercode, | 		Who:            usercode, | ||||||
| @@ -79,9 +88,11 @@ func (dbobj dbcon) createConsentRecord(userTOKEN string, mode string, usercode s | |||||||
| 		Brief:          brief, | 		Brief:          brief, | ||||||
| 		Message:        message, | 		Message:        message, | ||||||
| 		Status:         status, | 		Status:         status, | ||||||
|  | 		Freetext:       freetext, | ||||||
| 		Lawfulbasis:    lawfulbasis, | 		Lawfulbasis:    lawfulbasis, | ||||||
| 		Consentmethod:  consentmethod, | 		Consentmethod:  consentmethod, | ||||||
| 		Referencecode:  referencecode, | 		Referencecode:  referencecode, | ||||||
|  | 		Lastmodifiedby: lastmodifiedby, | ||||||
| 	} | 	} | ||||||
| 	// 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)) | ||||||
|   | |||||||
| @@ -956,9 +956,13 @@ func initConsent(db *sql.DB) error { | |||||||
| 	  brief STRING, | 	  brief STRING, | ||||||
| 	  status STRING, | 	  status STRING, | ||||||
| 	  message STRING, | 	  message STRING, | ||||||
|  | 	  freetext STRING, | ||||||
| 	  lawfulbasis STRING, | 	  lawfulbasis STRING, | ||||||
| 	  consentmethod STRING, | 	  consentmethod STRING, | ||||||
| 	  referencecode STRING, | 	  referencecode STRING, | ||||||
|  | 	  lastmodifiedby STRING, | ||||||
|  | 	  creationtime int, | ||||||
|  | 	  starttime int, | ||||||
| 	  endtime int, | 	  endtime int, | ||||||
| 	  ` + "`when` int);") | 	  ` + "`when` int);") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 stremovsky
					stremovsky