/
lbasis_api.go
116 lines (111 loc) · 3.28 KB
/
lbasis_api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"fmt"
"net/http"
"reflect"
"github.com/julienschmidt/httprouter"
//"go.mongodb.org/mongo-driver/bson"
)
func (e mainEnv) createLegalBasis(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
brief := ps.ByName("brief")
authResult := e.enforceAdmin(w, r)
if authResult == "" {
return
}
brief = normalizeBrief(brief)
if isValidBrief(brief) == false {
returnError(w, r, "bad brief format", 405, nil, nil)
return
}
records, err := getJSONPostMap(r)
if err != nil {
returnError(w, r, "failed to decode request body", 405, err, nil)
return
}
newbrief := getStringValue(records["brief"])
if len(newbrief) > 0 && newbrief != brief {
if isValidBrief(newbrief) == false {
returnError(w, r, "bad brief format", 405, nil, nil)
return
}
}
status := getStringValue(records["status"])
module := getStringValue(records["module"])
fulldesc := getStringValue(records["fulldesc"])
shortdesc := getStringValue(records["shortdesc"])
basistype := getStringValue(records["basistype"])
requiredmsg := getStringValue(records["requiredmsg"])
usercontrol := false
requiredflag := false
if status != "disabled" {
status = "active"
}
if value, ok := records["usercontrol"]; ok {
if reflect.TypeOf(value).Kind() == reflect.Bool {
usercontrol = value.(bool)
} else {
num := value.(int32)
if num > 0 {
usercontrol = true
}
}
}
if value, ok := records["requiredflag"]; ok {
if reflect.TypeOf(value).Kind() == reflect.Bool {
requiredflag = value.(bool)
} else {
num := value.(int32)
if num > 0 {
requiredflag = true
}
}
}
e.db.createLegalBasis(brief, newbrief, module, shortdesc, fulldesc, basistype, requiredmsg, status, usercontrol, requiredflag)
/*
notifyURL := e.conf.Notification.NotificationURL
if newStatus == true && len(notifyURL) > 0 {
// change notificate on new record or if status change
if len(userTOKEN) > 0 {
notifyConsentChange(notifyURL, brief, status, "token", userTOKEN)
} else {
notifyConsentChange(notifyURL, brief, status, mode, identity)
}
}
*/
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
w.Write([]byte(`{"status":"ok"}`))
}
func (e mainEnv) deleteLegalBasis(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
brief := ps.ByName("brief")
authResult := e.enforceAdmin(w, r)
if authResult == "" {
return
}
brief = normalizeBrief(brief)
if isValidBrief(brief) == false {
returnError(w, r, "bad brief format", 405, nil, nil)
return
}
e.db.unlinkProcessingActivityBrief(brief)
e.db.deleteLegalBasis(brief)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
w.Write([]byte(`{"status":"ok"}`))
}
func (e mainEnv) listLegalBasisRecords(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
authResult := e.enforceAdmin(w, r)
if authResult == "" {
return
}
resultJSON, numRecords, err := e.db.getLegalBasisRecords()
if err != nil {
returnError(w, r, "internal error", 405, err, nil)
return
}
fmt.Printf("Total count of rows: %d\n", numRecords)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
str := fmt.Sprintf(`{"status":"ok","total":%d,"rows":%s}`, numRecords, resultJSON)
w.Write([]byte(str))
}