Add consent tracking endpoint
This commit is contained in:
parent
ac343861ad
commit
b6ee34918c
|
@ -36,6 +36,7 @@ import (
|
||||||
func AddPublicRoutes(
|
func AddPublicRoutes(
|
||||||
router *mux.Router,
|
router *mux.Router,
|
||||||
synapseAdminRouter *mux.Router,
|
synapseAdminRouter *mux.Router,
|
||||||
|
consentAPIMux *mux.Router,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
accountsDB accounts.Database,
|
accountsDB accounts.Database,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *gomatrixserverlib.FederationClient,
|
||||||
|
@ -57,7 +58,7 @@ func AddPublicRoutes(
|
||||||
}
|
}
|
||||||
|
|
||||||
routing.Setup(
|
routing.Setup(
|
||||||
router, synapseAdminRouter, cfg, eduInputAPI, rsAPI, asAPI,
|
router, synapseAdminRouter, consentAPIMux, cfg, eduInputAPI, rsAPI, asAPI,
|
||||||
accountsDB, userAPI, federation,
|
accountsDB, userAPI, federation,
|
||||||
syncProducer, transactionsCache, fsAPI, keyAPI, extRoomsProvider, mscCfg,
|
syncProducer, transactionsCache, fsAPI, keyAPI, extRoomsProvider, mscCfg,
|
||||||
)
|
)
|
||||||
|
|
47
clientapi/routing/consent_tracking.go
Normal file
47
clientapi/routing/consent_tracking.go
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
package routing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The data used to populate the /consent request
|
||||||
|
type constentTemplateData struct {
|
||||||
|
User string
|
||||||
|
Version string
|
||||||
|
UserHMAC string
|
||||||
|
HasConsented bool
|
||||||
|
PublicVersion bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func consent(userAPI userapi.UserInternalAPI, cfg *config.ClientAPI) http.HandlerFunc {
|
||||||
|
consentCfg := cfg.Matrix.UserConsentOptions
|
||||||
|
return func(writer http.ResponseWriter, req *http.Request) {
|
||||||
|
if !consentCfg.Enabled() {
|
||||||
|
writer.WriteHeader(http.StatusBadRequest)
|
||||||
|
_, _ = writer.Write([]byte("consent tracking is disabled"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch req.Method {
|
||||||
|
case http.MethodGet:
|
||||||
|
// The data used to populate the /consent request
|
||||||
|
data := constentTemplateData{
|
||||||
|
User: req.FormValue("u"),
|
||||||
|
Version: req.FormValue("v"),
|
||||||
|
UserHMAC: req.FormValue("h"),
|
||||||
|
}
|
||||||
|
// display the privacy policy without a form
|
||||||
|
data.PublicVersion = data.User == "" || data.UserHMAC == "" || data.Version == ""
|
||||||
|
|
||||||
|
err := consentCfg.Templates.ExecuteTemplate(writer, consentCfg.Version+".gohtml", data)
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithError(err).Error("unable to print consent template")
|
||||||
|
}
|
||||||
|
case http.MethodPost:
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -47,7 +47,7 @@ import (
|
||||||
// applied:
|
// applied:
|
||||||
// nolint: gocyclo
|
// nolint: gocyclo
|
||||||
func Setup(
|
func Setup(
|
||||||
publicAPIMux, synapseAdminRouter *mux.Router, cfg *config.ClientAPI,
|
publicAPIMux, synapseAdminRouter, consentAPIMux *mux.Router, cfg *config.ClientAPI,
|
||||||
eduAPI eduServerAPI.EDUServerInputAPI,
|
eduAPI eduServerAPI.EDUServerInputAPI,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||||
|
@ -117,6 +117,9 @@ func Setup(
|
||||||
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unspecced consent tracking
|
||||||
|
consentAPIMux.HandleFunc("/consent", consent(userAPI, cfg)).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
||||||
|
|
||||||
r0mux := publicAPIMux.PathPrefix("/r0").Subrouter()
|
r0mux := publicAPIMux.PathPrefix("/r0").Subrouter()
|
||||||
unstableMux := publicAPIMux.PathPrefix("/unstable").Subrouter()
|
unstableMux := publicAPIMux.PathPrefix("/unstable").Subrouter()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue