mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-23 06:41:56 -06:00
Add consent tracking endpoint
This commit is contained in:
parent
ac343861ad
commit
b6ee34918c
|
@ -36,6 +36,7 @@ import (
|
|||
func AddPublicRoutes(
|
||||
router *mux.Router,
|
||||
synapseAdminRouter *mux.Router,
|
||||
consentAPIMux *mux.Router,
|
||||
cfg *config.ClientAPI,
|
||||
accountsDB accounts.Database,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
|
@ -57,7 +58,7 @@ func AddPublicRoutes(
|
|||
}
|
||||
|
||||
routing.Setup(
|
||||
router, synapseAdminRouter, cfg, eduInputAPI, rsAPI, asAPI,
|
||||
router, synapseAdminRouter, consentAPIMux, cfg, eduInputAPI, rsAPI, asAPI,
|
||||
accountsDB, userAPI, federation,
|
||||
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:
|
||||
// nolint: gocyclo
|
||||
func Setup(
|
||||
publicAPIMux, synapseAdminRouter *mux.Router, cfg *config.ClientAPI,
|
||||
publicAPIMux, synapseAdminRouter, consentAPIMux *mux.Router, cfg *config.ClientAPI,
|
||||
eduAPI eduServerAPI.EDUServerInputAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||
|
@ -117,6 +117,9 @@ func Setup(
|
|||
).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()
|
||||
unstableMux := publicAPIMux.PathPrefix("/unstable").Subrouter()
|
||||
|
||||
|
|
Loading…
Reference in a new issue